Lesson 2 of 2 Amazon VPC and Route 53

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.

Alias record
Points toAWS resources: load balancers, CloudFront, API Gateway custom domains, S3 websites
Works at the zone apex (example.com)?Yes
Query costFree
CNAME record
Points toAny hostname
Works at the zone apex (example.com)?No
Query costCharged

Private 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.

PolicyUse for
SimpleOne resource
WeightedSplitting traffic, such as 10% to a new version
Latency-basedSending users to the lowest-latency Region
FailoverActive-passive disaster recovery
GeolocationRouting by the user's location
Multivalue answerReturning several healthy IP addresses
Sort into groups

Choose the routing policy

Exam skills 1.1.3 · 3.3.6

Choose the Route 53 routing policy for each requirement.

Log in to try this activity Interactive activities are free with an account.

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.

Worked example

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.

PracticeEffect
Lower the TTL to 60 s a day before a planned changeCaches expire quickly when the change happens
Use an alias record to the load balancerFollows the load balancer's IP changes automatically; no charge for queries
Use weighted records for a gradual moveShift 10%, then 50%, then 100% of traffic

After the move is complete and stable, the TTL can be raised again to reduce query volume.

Check yourself

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.