【发布时间】:2021-05-12 09:19:44
【问题描述】:
我正在尝试获取欧盟(爱尔兰)区域 (eu-west-1) 的 GPU 实例价格。 然而,一些实例类型的价格为 0.00,尽管网站 (https://aws.amazon.com/ec2/pricing/on-demand/) 显示它们是可用的并且绝对不是 0.00。
我正在使用下面的代码:
session = boto3.Session(profile_name='nimbo')
instance_types = list(sorted(ec2_instance_types('eu-west-1')))
# Filter by p and g instance types (gpus)
instance_types = [inst for inst in instance_types if inst[0] in ["p", "g"]]
# Use AWS Pricing API at US-East-1
pricing = session.client('pricing', region_name='us-east-1')
for instance_type in instance_types:
response = pricing.get_products(
ServiceCode='AmazonEC2',
MaxResults=1,
FormatVersion='aws_v1',
Filters=[
{ 'Type': 'TERM_MATCH', 'Field': 'instanceType', 'Value': instance_type },
{ 'Type': 'TERM_MATCH', 'Field': 'location', 'Value': 'EU (Ireland)' },
{ 'Type': 'TERM_MATCH', 'Field': 'operatingSystem', 'Value': 'Linux' },
]
)
inst = json.loads(response["PriceList"][0])
inst = inst['terms']['OnDemand']
inst = list(inst.values())[0]
inst = list(inst["priceDimensions"].values())[0]
inst = inst['pricePerUnit']
currency = list(inst.keys())[0]
price = float(inst[currency])
print(instance_type+": "+"%0.3f %s"%(price, currency))
这会返回:
g2.2xlarge: 0.907 USD
g2.8xlarge: 0.000 USD
g3.16xlarge: 0.000 USD
g3.4xlarge: 1.331 USD
g3.8xlarge: 2.420 USD
g3s.xlarge: 0.796 USD
g4ad.16xlarge: 0.000 USD
g4ad.4xlarge: 0.000 USD
g4ad.8xlarge: 2.130 USD
g4dn.12xlarge: 4.645 USD
g4dn.16xlarge: 0.000 USD
g4dn.2xlarge: 0.838 USD
g4dn.4xlarge: 1.342 USD
g4dn.8xlarge: 0.000 USD
g4dn.metal: 8.724 USD
g4dn.xlarge: 0.625 USD
p2.16xlarge: 0.000 USD
p2.8xlarge: 7.776 USD
p2.xlarge: 0.000 USD
p3.16xlarge: 0.000 USD
p3.2xlarge: 3.305 USD
p3.8xlarge: 14.082 USD
p3dn.24xlarge: 0.000 USD
p4d.24xlarge: 0.000 USD
有人知道我在这里缺少什么吗?
【问题讨论】:
标签: python amazon-web-services amazon-s3 amazon-ec2 boto3