TExcelTAD
Home › AWS Cloud › Amazon Route 53

Amazon Route 53

Amazon Route 53 is AWS's DNS service (named after DNS's port, 53). It does three jobs:

  1. Domain registration: buy and renew domain names like example.com.
  2. DNS hosting: answer queries for your domains from a global network of servers, in hosted zones (public for the internet, private for inside VPCs).
  3. Health checks and traffic routing: send users to healthy, nearby or weighted endpoints.

Record types

Type Maps a name to Example
A / AAAA IPv4 / IPv6 address www → 203.0.113.10
CNAME Another name (not allowed at the zone apex) blog → myblog.example.net
Alias (Route 53 feature) An AWS resource: ALB, CloudFront, S3 website, API Gateway example.com → my-alb-123.eu-west-1.elb.amazonaws.com
MX Mail servers 10 mail.example.com
TXT Text (domain verification, SPF) "v=spf1 include:amazonses.com ~all"
NS / SOA The zone's name servers / authority info created automatically

Alias records work at the zone apex (example.com itself), follow the AWS resource's IP changes automatically, and queries to them are free.

bash
aws route53 change-resource-record-sets --hosted-zone-id Z0123456789ABCDEFGHIJ \
    --change-batch file://www-record.json
dig +short www.example.com
json
{
  "Changes": [{
    "Action": "UPSERT",
    "ResourceRecordSet": {
      "Name": "www.example.com",
      "Type": "A",
      "AliasTarget": {
        "HostedZoneId": "Z32O12XQLNTSW2",
        "DNSName": "shop-alb-1234567890.eu-west-1.elb.amazonaws.com",
        "EvaluateTargetHealth": true
      }
    }
  }]
}

Sample output of dig:

text
52.18.112.40
34.249.7.198

Routing policies

Policy Answers with Use case
Simple One record (possibly several IPs) One resource
Weighted Records in proportion to weights Canary releases, A/B tests
Latency-based The Region with the lowest latency for the user Multi-Region apps
Failover Primary while healthy, otherwise secondary Active-passive disaster recovery
Geolocation Based on the user's country/continent Localised content, legal restrictions
Geoproximity Based on distance, with a bias Shifting traffic between Regions
Multivalue answer Up to 8 healthy records Simple client-side load balancing
IP-based Based on the client's IP range ISP-specific routing

Model: weighted routing

With weights 90 and 10, about 10% of DNS answers point to the new version. To keep the output deterministic, this model walks through 1,000 evenly spaced "dice rolls" instead of using a random generator:

python · try it yourself
records = [("v1-alb", 90), ("v2-alb", 10)]
total = sum(w for _, w in records)

def answer(roll):            # roll in [0, total)
    for name, weight in records:
        if roll < weight:
            return name
        roll -= weight

counts = {name: 0 for name, _ in records}
queries = 1000
for i in range(queries):
    counts[answer(i * total / queries)] += 1
for name, n in counts.items():
    print(f"{name}: {n} answers ({n / queries:.0%})")
v1-alb: 900 answers (90%)
v2-alb: 100 answers (10%)

A weight of 0 stops traffic to a record entirely, which is handy for rolling back a canary.

Model: latency and failover routing

python · try it yourself
latency_ms = {   # example measurements from users to Regions
    "Berlin":    {"eu-central-1": 8,   "us-east-1": 95,  "ap-northeast-1": 240},
    "Chicago":   {"eu-central-1": 105, "us-east-1": 22,  "ap-northeast-1": 150},
    "Seoul":     {"eu-central-1": 260, "us-east-1": 180, "ap-northeast-1": 35},
}
healthy = {"eu-central-1": True, "us-east-1": True, "ap-northeast-1": False}

def latency_route(city):
    options = {r: ms for r, ms in latency_ms[city].items() if healthy[r]}
    return min(options, key=options.get)

def failover_route(primary, secondary):
    return primary if healthy[primary] else secondary

for city in latency_ms:
    print(f"latency  {city:<8} -> {latency_route(city)}")
print("failover primary us-east-1      ->", failover_route("us-east-1", "eu-central-1"))
healthy["us-east-1"] = False
print("failover after us-east-1 fails  ->", failover_route("us-east-1", "eu-central-1"))
print("latency  Chicago now            ->", latency_route("Chicago"))
latency  Berlin   -> eu-central-1
latency  Chicago  -> us-east-1
latency  Seoul    -> us-east-1
failover primary us-east-1      -> us-east-1
failover after us-east-1 fails  -> eu-central-1
latency  Chicago now            -> eu-central-1

Seoul's closest Region (ap-northeast-1) is unhealthy, so Route 53 answers with the next-best healthy Region. That only works when records are linked to health checks (or alias records with EvaluateTargetHealth).

TTL and caching

DNS answers are cached by resolvers for the record's TTL (time to live, in seconds). A long TTL (e.g. 86400) means fewer queries but slow changes; a short TTL (60) lets failover take effect quickly. Lower the TTL before a planned migration.

Test yourself

Which record type can point the zone apex example.com to an Application Load Balancer?

  1. CNAME
  2. MX
  3. Alias A record
  4. TXT

You want 5% of users to get a new release. Which routing policy fits?

  1. Simple
  2. Weighted
  3. Geolocation
  4. Multivalue

What does failover routing need in order to switch to the secondary?

  1. A long TTL
  2. A health check on the primary
  3. Two hosted zones
  4. CloudFront