Sub topic 3
Availability Zones: isolated locations within a Region
What this chapter assumes
You have an AWS account and can run commands in a terminal. You know what a virtual server and a block of storage are, and you know what a network and an IP address are. The previous chapter covered Regions. Here you will work with the smaller unit inside a Region: the Availability Zone.
What an Availability Zone is
An Availability Zone (AZ) is one or more discrete data centers inside a Region. Each AZ has its own power, cooling, and physical security. AZs in the same Region are connected by a private, high-bandwidth, low-latency network.
AWS places AZs far enough apart that a single event, such as a fire, flood, or power failure, is unlikely to affect more than one of them. They are also close enough together that traffic between them takes only a few milliseconds. This lets you replicate data synchronously between AZs without a large delay.
Most Regions have three or more AZs. Some older or smaller Regions have fewer, so check the Region you plan to use instead of assuming three. Each AZ is named after its Region plus a letter, such as us-east-1a.
The diagram shows how one Region contains several AZs, and how each AZ contains one or more data centers.
What isolation does and does not give you
Isolation means that a failure in one AZ should stay in that AZ. It does not mean the AZ never fails. It also does not protect you from problems that affect the whole Region.
| Event | Contained by an AZ boundary? |
|---|---|
| Power loss in one data center building | Yes |
| Flooding or fire at one site | Yes |
| A bad deployment you push to every AZ | No |
| A Regional service control plane issue | Often no |
| A deleted resource or wrong IAM policy | No |
Spreading a workload across AZs protects you from facility-level failures. It does not protect you from your own mistakes or from a problem in a Regional service. For those you need other tools, such as staged deployments, backups, and sometimes a second Region.
Where AZs show up in practice
You meet AZs when you create resources that must live in a specific physical place. Two common cases:
- Subnets. A subnet in a Virtual Private Cloud (VPC) lives in exactly one AZ. It cannot span two. To cover two AZs you create two subnets.
- Instances and volumes. An EC2 instance runs in one AZ, chosen through its subnet. An EBS volume also lives in one AZ, and it can only attach to an instance in the same AZ.
Many managed services hide the AZ detail. For example, an Amazon S3 bucket belongs to a Region, and S3 stores your data across multiple AZs for you. The next chapter on resource scope covers this split in more detail.
Listing AZs with the CLI
The describe-availability-zones command lists the AZs for a Region. This example prints four fields for each zone: the name, the ID, the state, and the zone type.
aws ec2 describe-availability-zones --region us-east-1 \
--query "AvailabilityZones[].[ZoneName,ZoneId,State,ZoneType]" \
--output tableThe output has one row per zone. The ZoneName column holds values like us-east-1a. The ZoneId column holds values like use1-az1. The State column is normally available. The ZoneType column is availability-zone for a standard AZ. Local Zones and Wavelength Zones show other values, and a later chapter covers them.
Two behaviors are worth knowing:
- By default the command lists only zones that are available to your account. Add
--all-availability-zonesto include zones that need opt-in, such as Local Zones you have not enabled. - The command only reports zones for the Region you point it at. A call with no Region set uses your configured default.
Listing AZs with boto3
The same call works from Python. This script keeps only standard AZs by filtering on zone-type, which removes Local Zones and Wavelength Zones from the result.
import boto3
ec2 = boto3.client("ec2", region_name="us-east-1")
response = ec2.describe_availability_zones(
Filters=[{"Name": "zone-type", "Values": ["availability-zone"]}]
)
for az in response["AvailabilityZones"]:
print(az["ZoneName"], az["ZoneId"], az["State"])Each item in AvailabilityZones is a dictionary. Besides the three fields printed here, it includes RegionName, ZoneType, ParentZoneName (for extended zones), and OptInStatus.
A good habit is to read the list of AZs at run time instead of hard-coding names like us-east-1a. Not every account sees the same set of zones, and AWS can add zones to a Region over time. Code that asks the API stays correct when that happens.
Zone state and capacity
The State field tells you whether a zone is usable. Most of the time it is available. A value such as impaired or unavailable signals a problem, although in practice AWS also reports issues through the AWS Health Dashboard, so check there during an incident.
Capacity is a separate matter. An AZ can be healthy and still not have capacity for a specific instance type at a given moment. If a launch fails with an InsufficientInstanceCapacity error, the usual fixes are:
- Retry the launch in a different AZ in the same Region.
- Try a different instance size or family.
- Wait and retry later.
Because of this, a design that can launch into any of several AZs is easier to operate than one pinned to a single zone.
Names are not the same as IDs
The names us-east-1a and us-east-1b look like fixed labels, but AWS maps each name to a physical zone separately for every account. Your us-east-1a can be a different physical zone from another account's us-east-1a. AWS does this to spread load, because many people would otherwise pick the first letter.
The AZ ID, such as use1-az1, identifies the same physical zone in every account. This matters when two accounts must place resources in the same zone, for example to keep traffic between them inside one AZ. A later chapter covers the mapping in detail. For now, remember two points:
- Use the name for casual work and for resources inside a single account.
- Use the ID when you coordinate across accounts.
You can create a subnet by ID instead of by name:
aws ec2 create-subnet \
--vpc-id vpc-0123456789abcdef0 \
--cidr-block 10.0.1.0/24 \
--availability-zone-id use1-az1The VPC ID here is a placeholder. Replace it with the ID of a VPC in your account. The command creates a subnet with the range 10.0.1.0/24 in the physical zone use1-az1, whatever name your account gives that zone.
Common errors and how to read them
| Symptom | Likely cause | What to do |
|---|---|---|
| `InvalidParameterValue` naming an AZ | The zone name does not exist in the Region you are calling | Check the Region setting, then list zones in that Region |
| Fewer AZs than you expected | The Region has fewer zones, or your account only sees some of them | List zones with the CLI and design for the number you see |
| `Unsupported` error for an instance type | The type is not offered in that AZ | Try another AZ or another type |
| EBS volume will not attach | The volume and the instance are in different AZs | Create a volume or snapshot restore in the instance's AZ |
| Cross-account traffic crosses AZs unexpectedly | Names were used instead of IDs | Compare AZ IDs on both sides |
A frequent cause of confusion is a Region mismatch. If you copy a command that names us-east-1a while your default Region is eu-west-1, the call fails because that zone is not in that Region. Check the Region first.
Why AZs matter for design
Because an AZ is a failure boundary, it is also the unit you design around. A workload that runs in one AZ is exposed to anything that affects that AZ. A workload that runs in two or more AZs can lose one and continue, as long as the remaining AZs have enough capacity to carry the load.
That capacity point is easy to miss. If you run two servers in two AZs and each is 70 percent busy, losing one AZ pushes the survivor past 100 percent. Plan for the load after a loss, not only before it. A later chapter on multi-AZ design works through this.
AZs also affect cost. Data that moves between AZs in the same Region is usually billed per gigabyte in each direction, while traffic inside one AZ over private addresses is generally free. The chapter on cost covers this.
Summary of the working model
- A Region holds several AZs. An AZ holds one or more data centers.
- AZs are isolated from each other for facility-level failures and joined by fast private links.
- Subnets, instances, and EBS volumes are each tied to a single AZ.
- Names are mapped per account. IDs are the same for everyone.
- Healthy zones can still lack capacity, so keep your options open across zones.
Exercise
You run aws ec2 describe-availability-zones and your default Region is eu-west-1. A colleague in another account tells you to "put the database in us-east-1a", and you run a command naming that zone. What happens, and what two checks would you make before relying on the zone name when coordinating with your colleague's account?
Show answer
The command fails because us-east-1a is not a zone in eu-west-1, so the Region setting is wrong. Before relying on the name, first confirm the Region (with aws configure get region or the --region option). Second, compare AZ IDs such as use1-az1 on both accounts, because the same zone name can map to different physical zones in different accounts.
Exercise
A VPC has one subnet in one AZ with two EC2 instances, and you need the application to survive the loss of an AZ. List the minimum changes you would make to the network and the compute layout.
Show answer
Create a second subnet in a different AZ (a subnet cannot span AZs). Launch instances into both subnets, for example through an Auto Scaling group that spans both subnets, and put a load balancer in front of them. Size each AZ so the survivor can carry the full load after the other AZ is lost.