Amazon ec2 如何获取对给定实例类型有效的区域列表?
有些情况需要启动到特定区域,但并非所有实例都在所有区域中。尤其是Amazon ec2 如何获取对给定实例类型有效的区域列表?,amazon-ec2,boto3,Amazon Ec2,Boto3,有些情况需要启动到特定区域,但并非所有实例都在所有区域中。尤其是p3dn.24xlarge实例仅出现在弗吉尼亚州的2个区域 有人能推荐一种使用boto3为实例类型获取有效区域的方法吗 当通过UI启动时,我一直在使用“Spot Instance Pricing History”(现货实例定价历史)图来确定允许哪些区域 此代码片段为我提供了支持实例点类型的AZ列表(以及价格): import boto3 instanceType = 'p3dn.24xlarge' product = 'Linux
p3dn.24xlarge
实例仅出现在弗吉尼亚州的2个区域
有人能推荐一种使用boto3为实例类型获取有效区域的方法吗
当通过UI启动时,我一直在使用“Spot Instance Pricing History”(现货实例定价历史)图来确定允许哪些区域
此代码片段为我提供了支持实例点类型的AZ列表(以及价格):
import boto3
instanceType = 'p3dn.24xlarge'
product = 'Linux/UNIX (Amazon VPC)'
for region in boto3.client('ec2').describe_regions()['Regions']:
client = boto3.client('ec2', region_name=region['RegionName'])
for zone in [z['ZoneName'] for z in client.describe_availability_zones()['AvailabilityZones'] if z['State'] == 'available']:
try:
price = client.describe_spot_price_history(InstanceTypes=[instanceType],
MaxResults=1,
ProductDescriptions=[product],
AvailabilityZone=zone)['SpotPriceHistory'][0]['SpotPrice']
print("%s: %s" % (zone, price))
except IndexError: pass