Routing Users to Healthy Endpoints with Amazon Route 53
This lesson explains how Amazon Route 53, the AWS DNS service, gives applications friendly domain names and routes users to healthy endpoints.
Learning outcomes
After completing this lesson, you will be able to:
- Describe how hosted zones and A, CNAME and alias records work.
- Choose a routing policy, such as weighted, latency or failover, for a requirement.
- Explain how record TTLs affect how quickly DNS changes take effect.
Records and hosted zones
A hosted zone holds the DNS records for one domain, such as example.com. Records map names to values: an A record maps a name to an IPv4 address, and a CNAME record maps a name to another name, such as www.example.com to a load balancer's DNS name.
AWS resources such as load balancers and CloudFront distributions have DNS names whose IP addresses change, so they are referenced by name rather than by IP address. A CNAME record does this, but DNS rules forbid a CNAME at the zone apex, the domain itself, so example.com cannot be a CNAME. Route 53 solves this with alias records, a Route 53 extension that points a name, including the apex, at an AWS resource. Route 53 resolves the alias to the resource's current IP addresses itself and returns them as an ordinary A or AAAA answer, and queries for alias records that point to AWS resources are free. A CNAME is still needed to point at a name outside AWS. The following table summarises the differences.
example.com)?Yesexample.com)?NoPrivate hosted zones answer queries only from associated VPCs, giving internal services names such as db.internal.example.com.
Routing policies and health checks
A routing policy decides how Route 53 answers a query when a record has more than one possible value. Simple routing returns the single value of the record. Weighted routing returns each of several records in proportion to its weight, for example 90 to the current stack and 10 to a new one, which suits gradual migrations and tests of a new version.
Latency-based routing returns the record for the Region that gives the user the lowest network latency, for applications deployed in several Regions. Failover routing returns the primary record while its health check passes and the secondary record when it fails, which implements active-passive disaster recovery. Geolocation routing chooses a record by the user's continent or country, for example to serve content in the local language or to meet data residency rules. Multivalue answer routing returns up to eight healthy records at random, giving simple client-side load balancing.
Health checks test an endpoint, such as an HTTP path, from locations around the world. When attached to records, they make Route 53 stop returning unhealthy endpoints, which is essential for failover and useful with every other policy. The following table summarises the policies.
| Policy | Use for |
|---|---|
| Simple | One resource |
| Weighted | Splitting traffic, such as 10% to a new version |
| Latency-based | Sending users to the lowest-latency Region |
| Failover | Active-passive disaster recovery |
| Geolocation | Routing by the user's location |
| Multivalue answer | Returning several healthy IP addresses |
TTLs and changes
Resolvers cache DNS answers for the record's TTL, so changes and failovers take effect only when caches expire. Lower TTLs well before a planned migration to shorten the changeover.
A DNS change that seems ignored
A developer moves api.example.com to a new load balancer, but many users keep reaching the old one for hours. The record had a TTL of 86,400 seconds (one day), so resolvers cached the old answer.
| Practice | Effect |
|---|---|
| Lower the TTL to 60 s a day before a planned change | Caches expire quickly when the change happens |
| Use an alias record to the load balancer | Follows the load balancer's IP changes automatically; no charge for queries |
| Use weighted records for a gradual move | Shift 10%, then 50%, then 100% of traffic |
After the move is complete and stable, the TTL can be raised again to reduce query volume.
Why should example.com use an alias record rather than a CNAME to point to a load balancer?
Show answer
A CNAME is not allowed at the zone apex. An alias record can be used there, follows the load balancer's changing IP addresses and has no query charge for AWS targets.
Exam Tips
Remember for the exam
- To point the root domain at a load balancer, use an alias record, not a CNAME.
- To shift a percentage of DNS traffic to a new stack, use weighted routing.
- If a DNS change is not yet visible, wait for the old TTL to expire, and lower TTLs before future migrations.
- For internal DNS names for services in a VPC, use a Route 53 private hosted zone.