Sub topic 2
Regions and Availability Zones: where instances run
This chapter assumes you can use the AWS CLI with configured credentials, and that you know what a CIDR block is. It explains the two largest location concepts in EC2, Regions and Availability Zones (AZs). Almost every launch error about "not found" or "not in the same zone" traces back to them.
The two levels of location
A Region is a separate geographic area, such as us-east-1 (N. Virginia) or eu-west-1 (Ireland). Regions are independent of each other. Each has its own endpoints, its own resources, and its own copy of most services.
An Availability Zone is one or more data centers inside a Region. Each has its own power, cooling, and networking. AZs in a Region are connected by fast, low-latency links, but they are isolated enough that a failure in one is unlikely to affect the others. Most Regions have three or more AZs.
An instance runs in exactly one AZ. You pick the AZ indirectly, by choosing a subnet. Each subnet lives in one AZ, so the subnet decides the zone.
Choosing a Region
Four factors usually decide the Region:
| Factor | What to check |
|---|---|
| Latency | Pick a Region close to your users or to the systems your instances talk to. |
| Compliance and data residency | Some laws and contracts require data to stay in a country or area. EC2 does not move your data between Regions on its own. |
| Service and feature availability | New services and instance types often reach some Regions before others. |
| Price | The same instance type has a different hourly price in different Regions. |
List the Regions your account can use:
aws ec2 describe-regions \
--query 'Regions[].RegionName' \
--output textSome newer Regions are opt-in Regions. They are disabled by default, and you must enable them in your account settings before you can use them. Add --all-regions to see them with their status:
aws ec2 describe-regions \
--all-regions \
--query 'Regions[].[RegionName,OptInStatus]' \
--output tableTelling the CLI which Region to use
Every EC2 call goes to one Region. The CLI picks it in this order, highest priority first:
- The
--regionoption on the command. - The
AWS_REGIONorAWS_DEFAULT_REGIONenvironment variable. - The
regionvalue in your profile (set withaws configure set region eu-west-1).
If you see an empty result from describe-instances and your instance is "missing", you are most likely querying the wrong Region. Check this first.
Inspecting Availability Zones
List the zones in a Region, along with their zone IDs:
aws ec2 describe-availability-zones \
--region us-east-1 \
--query 'AvailabilityZones[].[ZoneName,ZoneId,State]' \
--output tableYou will see two identifiers for each zone. The zone name (us-east-1a) is what you use in most commands. The zone ID (use1-az1) is the same physical zone for every account.
The name-to-ID mapping is shuffled per account. My us-east-1a may be a different physical zone than yours. AWS does this to spread load so that not everyone's "a" zone is the busiest. When you coordinate with another account, for example to share a subnet or to keep resources in the same physical zone, compare zone IDs, not names.
Instance type availability varies by zone
Not every instance type is offered in every AZ. If a launch fails with an error about capacity or an unsupported zone, check where the type is offered:
aws ec2 describe-instance-type-offerings \
--location-type availability-zone \
--filters Name=instance-type,Values=t3.micro \
--region us-east-1 \
--query 'InstanceTypeOfferings[].Location' \
--output textThe output lists the zones that offer t3.micro. If your chosen subnet is in a zone that is not on the list, launch into a subnet in one that is.
What is regional and what is zonal
Knowing the scope of each resource prevents most mistakes. Regional resources are visible anywhere in the Region. Zonal resources are tied to one AZ.
| Resource | Scope | Consequence |
|---|---|---|
| VPC | Regional | One VPC spans all AZs in its Region. |
| Subnet | One AZ | The subnet decides where an instance runs. |
| Instance | One AZ | It cannot move to another zone while running. |
| EBS volume | One AZ | It attaches only to instances in the same AZ. |
| EBS snapshot | Regional | You can restore it into any AZ in the Region. |
| AMI | Regional | An AMI ID from one Region does not work in another. |
| Key pair | Regional | You must create or import it again in each Region. |
| Security group | Regional, tied to one VPC | It applies only to instances in that VPC. |
| Elastic IP | Regional | It can be associated with an instance in any AZ of that Region. |
Two consequences come up often:
- AMI IDs differ per Region. The same Amazon Linux image has a different
ami-...ID in each Region. Look it up in the Region you are launching in, as the SSM parameter in the launch chapter does. To use your own AMI elsewhere, copy it withaws ec2 copy-image. - Moving data across zones goes through a snapshot. To use an EBS volume in another AZ, snapshot it, then create a new volume from the snapshot in the target zone:
aws ec2 create-volume \
--snapshot-id snap-0123456789abcdef0 \
--availability-zone us-east-1b \
--volume-type gp3Designing for failure
An AZ can fail, and a single instance in one AZ is a single point of failure. The standard approach is to run copies of a workload in at least two AZs, behind a load balancer, so that losing one zone leaves the service running. A Region-wide failure is much rarer, and protecting against it means running in a second Region, which costs more and is more complex. Most applications stop at multi-AZ.
Spreading across AZs has a cost. Traffic between instances in different AZs of the same Region is billed per GB, while traffic inside one AZ over private IPs is not. A chatty database client in one zone talking to a database in another can produce a surprising bill, so keep the heaviest traffic paths inside one zone where you can.
Common errors
- "The image id '[ami-...]' does not exist": you used an AMI ID from a different Region.
- "The volume ... is not in the same availability zone as instance ...": you tried to attach a volume across zones. Restore from a snapshot into the right zone.
- "Unsupported" or "InsufficientInstanceCapacity" in a zone: the type is not offered, or is temporarily short of capacity, in that AZ. Try a subnet in another zone or a different type.
- A key pair or security group "not found": it exists in another Region or VPC.
Exercise
You created an EBS volume in us-east-1a, but your instance runs in a subnet in us-east-1b. The attach command fails. Why does it fail, and how do you get the data onto the instance?
Show answer
An EBS volume is zonal and attaches only to instances in the same AZ. Create a snapshot of the volume (snapshots are regional), then create a new volume from that snapshot with --availability-zone us-east-1b, and attach the new volume to the instance.
Exercise
Why should you compare zone IDs instead of zone names when coordinating with another AWS account?
Show answer
Zone names such as us-east-1a are mapped to physical zones differently for each account, so the same name can mean different zones. Zone IDs such as use1-az1 identify the same physical zone in every account.