Part 11 of Learn AWS from Scratch

DNS and Route 53: Your Site's Address

How a name like example.com turns into an address, what the record types mean, the difference between CNAME and Alias, Route 53's routing policies and health checks, and a hands-on that doesn't require buying a domain.

In this article
  1. How DNS works
  2. Route 53
  3. Routing policies
  4. Health checks
  5. A domain bought elsewhere
  6. Hands-on: weighted routing without buying a domain
  7. Summary
  8. Test yourself

The load balancer in our application from part seven has a name like web-alb-1234567890.eu-central-1.elb.amazonaws.com. Nobody is going to type that. Visitors want shop.example.com, and what connects the two is DNS.

This section is about the visitor's path to your application: the name in this part, speed in the next, then the private network everything lives in.

How DNS works

DNS is the internet's phone book: you ask with a name and it answers with an address. No single server knows everything, so the answer comes through a chain:

Browser Resolver Asks for you Root servers Go ask .com .com servers Go ask Route 53 Route 53 The address is 192.0.2.10 1 5 2 3 4
The resolver goes through the root servers, then the .com servers, then the domain's name servers, and brings the address back to the browser.
  1. Your browser asks the resolver, usually from your internet provider or a public service such as 1.1.1.1.
  2. The resolver asks the root servers, which point it to the .com servers.
  3. The .com servers point it to the domain's name servers.
  4. The domain's name servers give the final answer.
  5. The resolver returns the address to the browser and keeps it for the TTL, so the next person asking gets an instant answer.

These are the terms you'll come across:

Term Meaning
Domain example.com: the name you own
Subdomain blog.example.com: a name under it
Registrar The company you buy the name from
Hosted zone The container holding a domain's records
Record One entry: a name pointing to a value
TTL How long a resolver may remember the answer

Route 53

Route 53 is AWS's DNS service, named after DNS's port 53. It has three jobs: holding your domain's records and answering for them, registering domains, and watching your application's health and directing visitors accordingly. AWS commits to 100% availability for it.

Hosted zones

Type Answers whom Example
Public Anyone on the internet example.com
Private Only inside the VPCs you choose db.series.internal

Each costs about half a dollar a month, plus a small charge for queries.

Record types

Type Points to Example
A An IPv4 address blog.example.com to 192.0.2.10
AAAA An IPv6 address blog.example.com to 2001:db8::10
CNAME Another name www.example.com to example.com
NS The domain's name servers ns-1.awsdns-01.org
MX Mail servers mail.example.com
TXT Free text, such as proof of domain ownership v=spf1 ...

CNAME or Alias?

Here's a common problem: a CNAME can't be used on the root domain example.com, yet you want it to point at your load balancer. The solution is an Alias, a special type in Route 53:

CNAME Alias
Points to Any name AWS resources such as ALB, CloudFront and API Gateway
Root domain Not allowed Allowed
Queries Charged Free for AWS resources
TTL You set it Route 53 sets it
Target health Not followed Can be followed

The rule is simple: if the target is on AWS, use an Alias. Note that it can't point to an EC2 server's DNS name.

Choosing a TTL

  • A long TTL: fewer queries and lower cost, but any change takes time to spread.
  • A short TTL: changes spread quickly, but queries increase.

Routing policies

"Routing" here doesn't mean traffic passes through Route 53. It only chooses which answer to give, and the visitor then connects directly to that address.

Policy How it answers Common use
Simple One record, which can hold several values A single server
Weighted By percentages you set Trying a new version on 10% of visitors
Latency The Region with the lowest delay for the visitor An application in several Regions
Failover The primary while it's healthy, otherwise the secondary Disaster recovery
Geolocation By the visitor's country or continent Language or content by country
Geoproximity By distance, with each site's reach grown or shrunk Gradually shifting traffic between areas
IP-based By the visitor's IP range Networks you know about
Multivalue Up to 8 healthy records Simple spreading, not a replacement for a load balancer

Health checks

For Failover and the others to work, Route 53 has to know who's healthy:

Type How it checks
Endpoint Checkers around the world request your address over HTTP, HTTPS or TCP
Calculated Combines the results of several checks into one
CloudWatch alarm Relies on an alarm, which is the solution for private resources

The checkers come from the internet, so they can't reach a server in a private network, and your security group has to allow their ranges if you're checking a public target.

A domain bought elsewhere

Buying a domain and managing its records are two separate things. If you bought yours from another company and want Route 53 to answer for it:

  1. Create a public hosted zone with the domain's name.
  2. Copy the four name servers from its NS record.
  3. Paste them into the domain's settings at the company you bought it from.

Once the change spreads, Route 53 is the one answering.

If you have a network in your office, you can connect its DNS with AWS through Resolver endpoints: inbound lets your network ask about AWS's private names, and outbound lets AWS ask about your network's names. This needs a connection between the two networks, which is the subject of part fourteen.

Hands-on: weighted routing without buying a domain

A private hosted zone lets you try all this without a real domain. We'll use your web-1 server from part three, inside the default network. From CloudShell, create the private domain:

Bash
VPC_ID=$(aws ec2 describe-vpcs --filters Name=isDefault,Values=true \
  --query "Vpcs[0].VpcId" --output text)

ZONE_ID=$(aws route53 create-hosted-zone --name series.internal \
  --caller-reference "demo-$(date +%s)" \
  --vpc VPCRegion=$AWS_REGION,VPCId=$VPC_ID \
  --query HostedZone.Id --output text)

Now add two records for the same name, 80% for the old version and 20% for the new. The addresses are made up, because DNS only answers and doesn't connect to them:

Bash
CHANGES='{"Changes":[
  {"Action":"CREATE","ResourceRecordSet":{"Name":"app.series.internal","Type":"A","TTL":5,
    "SetIdentifier":"old","Weight":80,"ResourceRecords":[{"Value":"10.0.0.80"}]}},
  {"Action":"CREATE","ResourceRecordSet":{"Name":"app.series.internal","Type":"A","TTL":5,
    "SetIdentifier":"new","Weight":20,"ResourceRecords":[{"Value":"10.0.0.20"}]}}
]}'

aws route53 change-resource-record-sets \
  --hosted-zone-id "$ZONE_ID" --change-batch "$CHANGES"

Sign in to the server through EC2 Instance Connect and ask 20 times. It takes two minutes, because we wait for the TTL to expire each time:

Bash
sudo dnf install -y bind-utils

for i in $(seq 1 20); do
  dig +short app.series.internal
  sleep 6
done | sort | uniq -c

You'll see a split close to 16 and 4. Try dig +trace aws.amazon.com as well, and you'll see the chain from the diagram step by step.

If you have a domain, add an A record of the Alias kind pointing at your load balancer, and your site now has your name.

Bash
aws route53 change-resource-record-sets \
  --hosted-zone-id "$ZONE_ID" --change-batch "${CHANGES//CREATE/DELETE}"

aws route53 delete-hosted-zone --id "$ZONE_ID"

Summary

  • DNS turns a name into an address through a chain, and the answer is kept for the TTL.
  • Route 53 holds your records, and a hosted zone can be public or private.
  • If the target is on AWS, use an Alias, which works on the root domain.
  • Routing policies only choose the answer; traffic doesn't pass through them.
  • Health checks are what make Failover work.

Test yourself

Before you move on, try these questions to check you've got this part. Each one is a practical scenario, and the explanation appears once you answer.

Question 1 of 5

A bakery's site runs behind an Application Load Balancer, and the owner wants anyone typing the bare domain example.com to reach it. The load balancer's addresses can change at any time. Which record fits?

Show the answer

Correct answer: D

An Alias works on the root domain and follows the load balancer's changing addresses for you, and queries to AWS resources like this one are free.

  • A: A CNAME isn't allowed on the root domain.
  • B: Once the addresses change, the record points to the wrong place.
  • C: A TXT record holds free text, and browsers don't use it to find a server.

Review: CNAME or Alias? in this part, and Choosing between alias and non-alias records in the AWS docs.

Question 2 of 5

A streaming service runs in two Regions, Frankfurt and Bahrain. Its license requires visitors from Saudi Arabia to always get the Bahrain copy, even when Frankfurt would answer them faster. Which routing policy fits?

Show the answer

Correct answer: A

Geolocation chooses by where the visitor is rather than by speed, which is what a licensing rule needs.

  • B: This sends the visitor to the fastest Region, which could be Frankfurt.
  • C: This splits traffic by percentages, whatever the visitor's country.
  • D: This returns several healthy records, with no regard for country.

Review: Routing policies in this part, and Geolocation routing in the AWS docs.

Question 3 of 5

An internal application uses a Failover record in a private hosted zone. Its primary servers have only private addresses, and must stay that way. How should Route 53 learn whether the primary is healthy?

Show the answer

Correct answer: C

Route 53's checkers come from the internet, so they can't reach a private address. A CloudWatch alarm can watch a metric from the servers, and the health check follows the alarm.

  • A: The checkers are outside the network, and can't reach a private address.
  • B: This breaks the requirement that the servers stay private.
  • D: This only combines other checks, and those still can't reach the servers.

Review: Health checks in this part, and Configuring failover in a private hosted zone in the AWS docs.

Question 4 of 5

A startup bought its domain from another company and wants to keep the registration there, while Route 53 answers for the domain's records. What does it need to do?

Show the answer

Correct answer: B

Buying a name and answering for it are separate things. Once the registrar lists Route 53's name servers, Route 53 is the one answering.

  • A: A transfer is optional, and isn't needed to manage the records.
  • C: A private zone only answers inside the VPCs you choose, not for the public.
  • D: This lets an office network ask about private names, and has nothing to do with public answers.

Review: A domain bought elsewhere in this part, and Making Route 53 the DNS service for a domain that's in use in the AWS docs.

Question 5 of 5

A team wants to send 10% of visitors to a new version of its application, and to pull that traffic back within minutes if anything goes wrong. Which two steps fit? (Choose two.)

Show the answer

Correct answer: A + E

Weighted records split the answers by the shares you set, and a short TTL means a change reaches visitors quickly, since resolvers only remember an answer for that long.

  • B: This chooses by place, not by a share of visitors.
  • C: Resolvers would keep the old answer for up to a day, so going back would be slow.
  • D: A Simple record gives you no way to set a share.

Review: Routing policies and Choosing a TTL in this part, and Weighted routing in the AWS docs.

Your site now has a name, but its server is still in one place and the distant visitor is still waiting. In part twelve we bring it closer with CloudFront and Global Accelerator.