gpt4 book ai didi

amazon-web-services - 如何获取 Amazon EC2 Spot 实例中断率

转载 作者:行者123 更新时间:2023-12-05 08:50:33 30 4
gpt4 key购买 nike

我已经创建了一个脚本来获得最佳的按需价格,还可以查看相同实例的现货价格。 https://github.com/fuatu/awsEC2pricefinder

这是我在下面给出的输出。我想为每个实例设置另一列并显示“中断频率”。

(awspricing) ~/Projects/awspricing $ python awsEC2pricing.py -t 2 4
Records are up-to-date
--------------------------
vCPU: 2.00
RAM: 4.00
OS: Linux
Region: US East (N. Virginia)
--------------------------
Instance vCPU RAM OS PriceH PriceM SpotH SpotM
t3a.medium 2.00 4.00 Linux 0.03760 27.07200 0.01140 8.20800
t3.medium 2.00 4.00 Linux 0.04160 29.95200 0.01250 9.00000
t2.medium 2.00 4.00 Linux 0.04640 33.40800 0.01430 10.29600
a1.large 2.00 4.00 Linux 0.05100 36.72000 0.01990 14.32800
t3a.large 2.00 8.00 Linux 0.07520 54.14400 0.02260 16.27200
m6g.large 2.00 8.00 Linux 0.07700 55.44000 0.00000 0.00000

您可以在此处查看“中断频率”百分比:https://aws.amazon.com/ec2/spot/instance-advisor/

我用谷歌搜索并检查了 boto3 ec2 方法,但找不到任何获取中断率的选项。因此,欢迎任何帮助展示如何以编程方式获取此数据的帮助。

最佳答案

我从同事那里找到了解决方案。

此链接有中断率。 https://spot-bid-advisor.s3.amazonaws.com/spot-advisor-data.json

我也相应地更新了我的代码

此处示例代码:

def get_ec2_spot_interruption(instances=[], os=None, region=None) -> defaultdict(None):
import requests
import json
results = defaultdict(None)
url_interruptions = "https://spot-bid-advisor.s3.amazonaws.com/spot-advisor-data.json"
try:
response = requests.get(url=url_interruptions)
spot_advisor = json.loads(response.text)['spot_advisor']
except requests.exceptions.ConnectionError:
return
rates = {
0: "<5%",
1: "5-10%",
2: "10-15%",
3: "15-20%",
4: ">20%"
}
for ii in instances:
try:
rate = spot_advisor[region][os][ii]['r']
results[ii] = rates[rate]
except KeyError:
results[ii] = ""
return results

关于amazon-web-services - 如何获取 Amazon EC2 Spot 实例中断率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61523868/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com