Sub topic 2
Regions and Availability Zones: where instances run
This chapter assumes you have an AWS account, can use the AWS CLI, and know what an IP address and a CIDR block are. It explains the two location choices you make before an instance exists: the Region and the Availability Zone.
Regions
A Region is a separate geographic area, such as us-east-1 (N. Virginia) or eu-west-1 (Ireland). Each Region is independent. Most resources, including instances, AMIs, security groups, and key pairs, belong to one Region and do not appear in the others.
Consider these factors when you pick a Region:
- Latency: choose a Region close to your users.
- Compliance: some rules require data to stay in a specific country or area.
- Service availability: not every service or instance type exists in every Region.
- Price: the same instance type can cost different amounts in different Regions.
The Region you use comes from the --region option, the AWS_REGION environment variable, or your CLI profile. Many "my instance disappeared" problems come from looking at the wrong Region in the console or CLI.
Availability Zones
An Availability Zone (AZ) is one or more data centers inside a Region, with independent power, cooling, and networking. AZs in a Region are connected by fast, low-latency links. A failure in one AZ is unlikely to affect another.
An instance runs in exactly one AZ. You pick the AZ indirectly, by choosing a subnet. Each subnet lives in one AZ, so launching into a subnet places the instance in that subnet's AZ. The next chapters cover subnets in detail.
Listing the zones in a Region
This command shows the zones your account can use in a Region:
aws ec2 describe-availability-zones \
--region us-east-1 \
--query 'AvailabilityZones[].[ZoneName,ZoneId,State]' \
--output tableThe output has two identifiers. ZoneName (for example us-east-1a) is mapped per account, so your us-east-1a may be a different physical zone from another account's. ZoneId (for example use1-az1) is the same for everyone. Use the zone ID when you need to match zones across accounts.
Designing for failure
Because an AZ can fail, a single instance is a single point of failure. The usual pattern is to run copies of a workload in subnets in at least two AZs. Later chapters on scaling cover how a load balancer and an Auto Scaling group automate this.
Storage and traffic also follow AZ boundaries:
| Resource | Scope |
|---|---|
| Instance | One AZ |
| EBS volume | One AZ, attached only to instances in that AZ |
| Subnet | One AZ |
| VPC | One Region, spanning all its AZs |
| AMI | One Region (copyable to others) |
Traffic between AZs in a Region is usually billed per GB, while traffic inside one AZ over private IPs is not. This is a small trade-off against resilience.
Exercise
You need to move an EBS volume from an instance in us-east-1a to an instance in us-east-1b. Why can't you attach it directly, and what is one way to move the data?
Show answer
An EBS volume lives in a single AZ and can attach only to instances in that AZ. Create a snapshot of the volume, then create a new volume from the snapshot in us-east-1b and attach that one.