Bootstrap FreeKB - Amazon Web Services (AWS) - List Availability Zones using the AWS CLI
Amazon Web Services (AWS) - List Availability Zones using the AWS CLI


This assumes you have already configured the aws command line tool. If not, check out my article on Getting Started with the AWS CLI.

An AWS region in a separate geographical location, such as us-east-1 (eastern USA) or eu-west-1 (western Europe) or ap-east-1 (eastern Asia). You typically want your AWS account to be in the region where most of your customers reside. For example, in the USA, there are 4 regions:

  • us-east-1
  • us-east-2
  • us-west-1
  • us-west-2

The aws ec2 describe-regions command can be used to list each AWS region. I've limited the output to only include the US regions, just to limit this example.

~]$ aws ec2 describe-regions
{
    "Regions": [
        {
            "Endpoint": "ec2.us-east-1.amazonaws.com",
            "RegionName": "us-east-1",
            "OptInStatus": "opt-in-not-required"
        },
        {
            "Endpoint": "ec2.us-east-2.amazonaws.com",
            "RegionName": "us-east-2",
            "OptInStatus": "opt-in-not-required"
        },
        {
            "Endpoint": "ec2.us-west-1.amazonaws.com",
            "RegionName": "us-west-1",
            "OptInStatus": "opt-in-not-required"
        },
        {
            "Endpoint": "ec2.us-west-2.amazonaws.com",
            "RegionName": "us-west-2",
            "OptInStatus": "opt-in-not-required"
        }
    ]
}

 

Within each AWS region, there are Availabiltiy Zones which are isolated from each other. For example, the us-east-1 region has the following Availability Zones.

 

Why are there different Availability Zones?

Let's say you have a single EC2 instance running in a single Availability Zone, perhaps us-east-1a. And let's say something happens that causes the EC2 instances in the Availability Zone to be unavailable. Perhaps AWS makes a configuration change that causes the EC2 instance in the Availablity Zone to be unavailable. Or a natural disaster such as a tornado destroys the AWS data center in the Availability Zone that was running your EC2 instance. Or hackers hack into the data center and bring down the Availablity Zone. In these scenarios, since you had only a single EC2 instance in a single Availability Zone, whatever is running on your EC2 instance would be unavailable. It is for this reason that almost always, two or more EC2 instances that produce the same services are placed in diffferent Availability Zones so that if there is some issues with a particular Availability Zone, then the EC2 instance in a different Availability Zone should not be impacted. By the way, a load balancer is often used to balance requests across two or more EC2 instances in different Availability Zones.

It is somewhat common for subnets to be associated with a particular Availability Zone, perhaps something this.

 

For example, if you have a web app load balanced between two different EC2 instances, you would probably want each EC2 instance to be different Availability Zones, so that if there is some issue with one of the Availability Zones, your other EC2 instance should continue to function in the other Availability Zone.

The aws ec2 describe-availability-zones command can be used to list your Availability Zones.

~]$ aws ec2 describe-availability-zones
{
    "AvailabilityZones": [
        {
            "State": "available",
            "OptInStatus": "opt-in-not-required",
            "Messages": [],
            "RegionName": "us-east-1",
            "ZoneName": "us-east-1a",
            "ZoneId": "use1-az1",
            "GroupName": "us-east-1",
            "NetworkBorderGroup": "us-east-1",
            "ZoneType": "availability-zone"
        },
        {
            "State": "available",
            "OptInStatus": "opt-in-not-required",
            "Messages": [],
            "RegionName": "us-east-1",
            "ZoneName": "us-east-1b",
            "ZoneId": "use1-az2",
            "GroupName": "us-east-1",
            "NetworkBorderGroup": "us-east-1",
            "ZoneType": "availability-zone"
        },
        {
            "State": "available",
            "OptInStatus": "opt-in-not-required",
            "Messages": [],
            "RegionName": "us-east-1",
            "ZoneName": "us-east-1c",
            "ZoneId": "use1-az4",
            "GroupName": "us-east-1",
            "NetworkBorderGroup": "us-east-1",
            "ZoneType": "availability-zone"
        },
        {
            "State": "available",
            "OptInStatus": "opt-in-not-required",
            "Messages": [],
            "RegionName": "us-east-1",
            "ZoneName": "us-east-1d",
            "ZoneId": "use1-az6",
            "GroupName": "us-east-1",
            "NetworkBorderGroup": "us-east-1",
            "ZoneType": "availability-zone"
        },
        {
            "State": "available",
            "OptInStatus": "opt-in-not-required",
            "Messages": [],
            "RegionName": "us-east-1",
            "ZoneName": "us-east-1e",
            "ZoneId": "use1-az3",
            "GroupName": "us-east-1",
            "NetworkBorderGroup": "us-east-1",
            "ZoneType": "availability-zone"
        },
        {
            "State": "available",
            "OptInStatus": "opt-in-not-required",
            "Messages": [],
            "RegionName": "us-east-1",
            "ZoneName": "us-east-1f",
            "ZoneId": "use1-az5",
            "GroupName": "us-east-1",
            "NetworkBorderGroup": "us-east-1",
            "ZoneType": "availability-zone"
        }
    ]

 

And here is an example of how to limit the output using the --query option.

aws ec2 describe-availability-zones --query 'AvailabilityZones[?ZoneName==`us-east-1a`]'

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 410aae in the box below so that we can be sure you are a human.