Skip to content

Instantly share code, notes, and snippets.

@PaulDuvall
Created February 6, 2020 15:01
Show Gist options
  • Save PaulDuvall/f2f3c767b7e96402562e182ef9234b71 to your computer and use it in GitHub Desktop.
Save PaulDuvall/f2f3c767b7e96402562e182ef9234b71 to your computer and use it in GitHub Desktop.
import boto3
ec2 = boto3.client('ec2')
# Retrieves all regions/endpoints that work with EC2
aws_regions = ec2.describe_regions()
# Get a list of regions and then instantiate a new ec2 client for each region in order to get list of AZs for the region
for region in aws_regions['Regions']:
my_region_name = region['RegionName']
ec2_region = boto3.client('ec2', region_name=my_region_name)
my_region = [{'Name': 'region-name', 'Values': [my_region_name]}]
print ("Current Region is %s" % my_region_name)
aws_azs = ec2_region.describe_availability_zones(Filters=my_region)
for az in aws_azs['AvailabilityZones']:
zone = az['ZoneName']
print(zone)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment