Sub topic 8
AZ names versus AZ IDs
This chapter assumes you know what a Region and an Availability Zone (AZ) are, and that you can run AWS CLI commands against an account. It explains why the AZ name us-east-1a does not point to the same physical zone in every account, and which identifier to use when you need to coordinate placement.
The problem with names
Every AZ has two identifiers:
- AZ name: a label such as
us-east-1a. Console dropdowns and most API calls show it. - AZ ID: a label such as
use1-az1. It names one physical AZ and means the same thing in every AWS account.
AWS maps names to physical zones separately for each account. If every new account received us-east-1a as the first zone, that zone would carry a disproportionate share of the load. So one account's us-east-1a can be use1-az1, while another account's us-east-1a is use1-az4.
The mapping is fixed for an account once it exists. Your own names stay stable, so within one account the names are safe to use. The risk appears only when two accounts compare notes.
Looking up the mapping
The describe-availability-zones command returns both values for your account:
aws ec2 describe-availability-zones --region us-east-1 \
--query "AvailabilityZones[].[ZoneName,ZoneId,State,ZoneType]" \
--output tableRun it in two accounts and compare the ZoneName and ZoneId columns. The IDs will match as a set, but the pairings can differ.
In boto3, the filter below keeps only standard AZs. It leaves out Local Zones and Wavelength Zones, which also appear in this API:
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"])When the difference matters
You can ignore the mapping if one account owns the whole workload. It matters when two accounts must agree on a physical location:
- Shared subnets. With AWS Resource Access Manager, one account shares a subnet and other accounts launch resources into it. A subnet created in
us-east-1ain the owner account may sit in a different physical zone than the consumer'sus-east-1a. The consumer sees the shared subnet's AZ ID and should use it. - Latency and data transfer. Traffic between two AZs in a Region can incur a data transfer charge, and it has slightly higher latency than traffic inside one AZ. If two accounts want their resources in the same zone, they need matching AZ IDs, not matching names.
- Capacity conversations. If AWS Support or a colleague says a zone has an issue, ask for the AZ ID. A name only makes sense inside the account that used it.
Placing resources by AZ ID
Many EC2 APIs accept an AZ ID directly. This command creates a subnet in a chosen physical zone, regardless of which name your account gives it. The VPC ID is a placeholder:
aws ec2 create-subnet \
--vpc-id vpc-0123456789abcdef0 \
--cidr-block 10.0.1.0/24 \
--availability-zone-id use1-az1Pass --availability-zone-id or --availability-zone, not both. Check the service documentation for each API, because support for AZ IDs varies.
Common mistakes
| Mistake | Effect | Fix |
|---|---|---|
| Comparing AZ names between accounts | You believe two resources share a zone when they do not | Compare AZ IDs |
| Assuming `a` is the "first" or best zone | No such ranking exists, and a name carries no capacity meaning | Treat names as arbitrary labels |
| Hard-coding names in shared templates | Different accounts resolve them to different zones | Look up IDs per account or pass AZ IDs |
| Forgetting that IDs include a Region prefix | An ID such as `use1-az1` is invalid in `eu-west-1` | Use IDs only in their own Region |
Exercise
Account A and Account B each launch an instance in us-east-1a. A teammate says both instances are in the same data center building, so traffic between them is free of cross-AZ charges. What should you check, and why?
Show answer
Check the AZ IDs with aws ec2 describe-availability-zones. AWS maps AZ names to physical zones separately for each account, so us-east-1a in Account A may be use1-az1 while it is use1-az2 in Account B. Only matching AZ IDs show that two resources share a physical AZ.