此代码段提供了支持实例点类型的AZs列表(以及价格):
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