The kiosk with your binder
Say you run Bloom, a flower shop with branches all over the city. Visitors know the name Bloom, but not where any branch is. So they don't wander around: they ask their hotel's front desk, and the front desk asks the city's information kiosk.
The kiosk keeps a binder for your shop. Each card in it says something like "Bloom: 12 Old Town Road". When the front desk asks about Bloom, the kiosk reads the card and gives the street address back. That binder is called a hosted zone.
How does the front desk know which kiosk has your binder? The city's name register says so. When you first registered the name Bloom, you also wrote down "ask the kiosks on Market Square". There are four of those kiosks, each with the same binder, so one closing for lunch never leaves visitors lost.
Authoritative DNS for your domain
Amazon Route 53 is three things: an authoritative DNS service, a domain registrar and a health checker. The name comes from port 53, where DNS is served. It doesn't replace the resolver your users' devices talk to; it's the last server in the lookup chain described in DNS, the one that actually owns the answer.
- A hosted zone is the container for one domain's records (
example.comand its subdomains). Each record has a name, a type (A,AAAA,CNAME,MX,TXTand so on), a value and a TTL. - Creating a public hosted zone gives it an
NSrecord and anSOArecord automatically. TheNSrecord lists the zone's four name servers (its delegation set), with names likens-123.awsdns-15.com, normally one each under.com,.net,.organd.co.uk, which also spreads the risk across TLDs. - Delegation makes the zone live: the registrar puts those four name servers in the parent zone (
.com), so resolvers asking the.comservers are sent to Route 53. - Domain registration is a separate feature. You can register a domain in Route 53, in which case it creates the hosted zone and sets the name servers for you. You can also transfer a domain in (create the hosted zone first and move DNS before the registration), or keep the domain at another registrar and just point its name servers at your hosted zone.
Route 53 is a global service: hosted zones aren't tied to a Region, and the name servers answer from AWS's locations around the world.
A second binder for staff only
Bloom also has a staff-only yard behind the shops, with a stockroom and a workshop. Workers in the yard need directions too, but those directions are nobody else's business.
So the yard has its own help desk with its own binder, a private hosted zone. Only people inside the yard can ask it. A worker who asks "where's the order office?" is told the back-door address inside the yard. A visitor on the square asking the same question gets the public front-door address from the kiosk, and a visitor asking for "the stockroom" is told there's no such place at all.
Public and private hosted zones
| Public hosted zone | Private hosted zone | |
|---|---|---|
| Who can query it | Anyone on the internet | Only resources in the VPCs associated with it |
| Who answers | Route 53's public name servers | The Route 53 Resolver in each VPC (the VPC base address plus two) |
| Typical records | Your website, API, mail | Internal services, databases, *.internal names |
A private hosted zone is associated with one or more VPCs (see the VPC concept), and you can
associate more later, including VPCs in other accounts. The VPC needs both enableDnsSupport and
enableDnsHostnames turned on.
You can give a public and a private zone the same name, which is called split-horizon DNS: queries from inside the VPC get the private answer (for example the internal load balancer's private IPs), and everyone else gets the public one. A record that only exists in the private zone simply doesn't exist for the internet.
When a private zone matches the queried name, the VPC resolver answers from that zone only. If the private zone has no matching record, Resolver returns NXDOMAIN; it doesn't forward the query to the public zone of the same name. So with split-horizon you have to copy every public name that internal clients also need into the private zone.
A card that finds the address for you
Some of Bloom's counters are inside the big market hall, which the city runs. The market hall moves its entrances around now and then, so writing one street address on a card would soon be wrong.
One kind of card just says "ask about Market Hall instead". But the rules don't allow that kind of card on the front page of the binder, the page for the plain name "Bloom", because that page already holds the binder's own details and a redirect card must have a page to itself. And it makes the front desk ask a second question.
So the kiosk offers a smarter card, an alias record. It says "Bloom: wherever the market hall's entrance is today". When someone asks, the kiosk looks up the hall's current entrance itself and hands back a real street address, straight away. It's allowed on the front page, and the kiosk doesn't charge for answering it.
Alias records versus CNAME
A CNAME record says "this name is another name": www.example.com CNAME my-alb-123.us-east-1.elb.amazonaws.com.
The resolver then has to look up the target name too. The DNS standard says a CNAME can't coexist with any other
record of the same name, and the zone apex (example.com itself) always has SOA and NS records, so a
CNAME can't sit at the apex.
An alias record is Route 53's own extension. It's an ordinary A or AAAA (or other type) record whose value
Route 53 fills in at query time from an AWS resource. Targets include:
- Elastic Load Balancing load balancers (ALB, NLB, Classic; see load balancer)
- CloudFront distributions (see CloudFront)
- S3 buckets configured as static website endpoints (see S3)
- API Gateway custom domains, VPC interface endpoints, Global Accelerator, Elastic Beanstalk, AppSync custom domains
- another record in the same hosted zone
Resolvers only ever see plain A/AAAA answers, so an alias works at the apex. When the load balancer's IPs
change, the answers follow automatically. Alias queries to AWS resources such as load balancers, CloudFront, API
Gateway and S3 websites are free, while CNAME queries are charged. You can't set a TTL on an alias record: Route 53 uses the target's. With evaluate target health,
an alias to an ALB or NLB counts as unhealthy when any of its target groups has no healthy targets (this option isn't
available for CloudFront targets).
Use a CNAME for names outside AWS or outside your zone, such as shop.example.com CNAME shops.myshopify.com.
The kiosk's rules
Bloom has a west branch and an east branch, and has just opened a small trial branch. You can tell the kiosk how to choose which address to give. That rule is called a routing policy.
- Just one card: everybody gets the same address.
- Shares: "send nine visitors in ten to the west branch and one to the trial branch", to try the new branch out gently.
- Quickest trip: send each visitor to the branch they can reach fastest from where they are.
- By district: visitors from the east district go to the east branch, because it has staff who speak their language. Everyone else gets a "for everyone else" card.
- Nearest, with a nudge: send visitors to the closest branch, but make a big branch's catchment area larger.
- By street: visitors from a street you name, such as the big office block, go to the branch you pick for them.
- A short list: give several open branches at once, and let the visitor pick.
Routing policies
Several records with the same name and type form a group, and each record's routing policy decides which
ones Route 53 returns. Records in a group are told apart by a SetIdentifier.
| Policy | How it chooses | Typical use |
|---|---|---|
| Simple | One record, which may hold several values, returned in random order; no health checks | One resource |
| Weighted | Each record's Weight (0 to 255) divided by the group total | Canary and blue/green releases, A/B tests |
| Latency | The Region with the lowest measured latency from the query's network | Multi-Region apps |
| Failover | The primary while it's healthy, otherwise the secondary | Active-passive disaster recovery |
| Geolocation | The query's continent, country or US state; most specific match wins | Language, licensing, data residency |
| Geoproximity | Geographic distance to each resource, adjusted by a bias of -99 to 99 | Shifting traffic between areas |
| IP-based | The query's source network, matched against CIDR blocks you upload | Routing known ISPs or offices |
| Multivalue answer | Up to eight healthy records, chosen at random | Simple client-side spreading |
A few details matter in practice:
- Latency is based on measurements AWS takes over time, so a given user's answer can change.
- Geolocation returns no answer for unmatched locations unless you add a default record, so always add one.
- Weight 0 stops traffic to a record; if every record in the group has weight 0, they share traffic equally.
- Route 53 sees the resolver's address, not the user's, unless the resolver sends the EDNS Client Subnet extension. A user on a far-away public resolver can be routed as if they were where the resolver is.
- Multivalue is not a load balancer: clients pick one IP and cache it. Put an ALB behind DNS for real balancing (see Load balancing).
Policies can be nested by pointing an alias at another group, for example latency between Regions and then weighted between two stacks inside each Region.
Inspectors and the backup branch
A kiosk that sends visitors to a closed branch is worse than no kiosk. So Bloom hires inspectors in several towns, and every half a minute each one rings the main branch to check it answers. That regular call is a health check.
If the main branch misses three calls in a row, and hardly any inspectors can reach it, they tell the kiosk. The kiosk stops giving out the main branch's address and gives the backup branch's address instead. When the main branch answers again, the kiosk switches back.
Health checks and failover
A Route 53 health check comes in three kinds:
- Endpoint: health checkers in several AWS Regions send HTTP, HTTPS or TCP requests to an IP or domain name.
The interval is 30 seconds by default, or 10 seconds at a higher price. HTTP checks must connect within four
seconds and get a 2xx or 3xx status within two seconds after connecting; you can also require a string in the
response body. A Spring Boot app can expose
/actuator/healthfor this. - Calculated: healthy when at least N of its child health checks are healthy.
- CloudWatch alarm: follows the data stream of a CloudWatch alarm.
An endpoint check changes state after the failure threshold of consecutive results, 3 by default, and the endpoint counts as healthy only when more than 18% of the checkers report it healthy. Checkers run on the internet, outside your VPC, so they can't reach private IPs. For private resources, use a CloudWatch alarm check.
For failover routing, create a primary record with a health check and a secondary record. Route 53 returns the primary while it's healthy and the secondary otherwise. For alias records pointing at a load balancer, turn on evaluate target health instead of a separate check. If every record in a group is unhealthy, Route 53 answers as if they were all healthy, on the basis that some answer beats none.
Health checks drive the other policies too: an unhealthy record drops out of weighted, latency, geolocation and multivalue answers.
Notes that last too long
The hotel front desk doesn't ask the kiosk every time. It writes the answer on a sticky note and reuses it for as long as the kiosk's card says, five minutes here. That time limit is the TTL.
That's fast, but it has a catch. If the main branch closes, the kiosk changes its answer at once, yet the front desk keeps handing out the old note until it runs out. Some guests even copy the address onto their hand and keep using it. So for a branch you might need to swap out quickly, have the kiosk mark its notes with a short time, and tell your guests not to keep copies for long.
TTLs, caching and failover speed
Route 53 changes its answer as soon as a health check fails, but resolvers and clients cache the old answer for the record's TTL. The real time to recover is roughly:
detection time (interval ร failure threshold, about 90 seconds with the defaults) + the record's TTL + any extra caching in the client.
- Use a TTL of 60 seconds or less on records with health checks. Shorter TTLs mean more queries (and a higher bill for non-alias records) but faster failover. Alias records use the target's TTL.
- Some resolvers and clients ignore or stretch TTLs, so a small amount of traffic keeps going to the old address for a while. Keep the old endpoint able to fail gracefully rather than switching it off at once.
- The JVM caches DNS too.
InetAddresscaches successful lookups for thenetworkaddress.cache.ttlsecurity property, and failed ones fornetworkaddress.cache.negative.ttl. The default is implementation-specific: OpenJDK caches for 30 seconds without a security manager, but forever with one. Set it explicitly in long-running services so the bound is one you chose:
1// At startup, before the first lookup (or set it in the JDK's java.security file)2java.security.Security.setProperty("networkaddress.cache.ttl", "30");
Records can also be changed from code. With the AWS SDK for Java v2, this shifts a weighted record to 10%:
1try (Route53Client r53 = Route53Client.builder().region(Region.AWS_GLOBAL).build()) {2r53.changeResourceRecordSets(r -> r3.hostedZoneId("Z0123456789ABCDEFGHIJ")4.changeBatch(b -> b.changes(c -> c5.action(ChangeAction.UPSERT)6.resourceRecordSet(s -> s7.name("api.example.com")8.type(RRType.A)9.setIdentifier("green")10.weight(10L)11.ttl(60L)12.resourceRecords(v -> v.value("203.0.113.20"))))));13}
Changes in a batch are applied together, and GetChange reports INSYNC once every Route 53 name server has them.