Amazon EC2 is hosted in multiple locations worldwide. These locations are composed of regions and Availability Zones. Each region is a separate geographic area. Each region has multiple, isolated locations known as Availability Zones. Amazon EC2 provides the ability to place instances and data in multiple locations.
In this example, Python code is used to get details about regions and Availability Zones. The code uses the AWS SDK for Python to get the data by using these methods of the EC2 client class:
For more information about regions and Availability Zones, see Regions and Availability Zones in the Amazon EC2 User Guide for Linux Instances or Regions and Availability Zones in the Amazon EC2 User Guide for Windows Instances.
All the example code for the Amazon Web Services (AWS) SDK for Python is available here on GitHub.
To set up and run this example, you must first configure your AWS credentials, as described in Quickstart.
The example below shows how to:
import boto3
ec2 = boto3.client('ec2')
# Retrieves all regions/endpoints that work with EC2
response = ec2.describe_regions()
print('Regions:', response['Regions'])
# Retrieves availability zones only for region of the ec2 object
response = ec2.describe_availability_zones()
print('Availability Zones:', response['AvailabilityZones'])