Route 53 & CloudFront
DNS and content delivery on AWS — Route 53 hosted zones, record types and alias records, routing policies (weighted, latency, failover, geolocation), health checks, private zones; CloudFront distributions, origins and behaviours, caching and cache keys, Origin Access Control for S3, invalidations, edge functions, security with WAF and Shield, and Global Accelerator.
Before a request reaches your load balancer it has to find it (DNS) and, ideally, be served from somewhere close to the user (CDN). On AWS those are Route 53 and CloudFront, both running on the global edge network. Background: DNS and CDNs.
Route 53
Route 53 is a highly available DNS service (the name is a nod to port 53), a domain registrar, and a health-checking system.
Hosted zones and records
- A public hosted zone answers queries from the internet for
example.com; a private hosted zone answers only inside associated VPCs (orders.internal). - Records:
A(IPv4),AAAA(IPv6),CNAME(alias to another name — not allowed at the zone apex),MX,TXT,NS,CAA,SRV. - Alias records are a Route 53 extension: they point a name — including the apex
example.com— at an AWS resource (ALB, CloudFront, S3 website, API Gateway), track its changing IPs automatically, and alias queries to AWS resources are free.
example.com A ALIAS → d1234abcd.cloudfront.net
api.example.com A ALIAS → my-alb-123.ap-south-1.elb.amazonaws.com
www.example.com CNAME example.com
example.com MX 10 mail.example.comTTL trades agility for cache efficiency: long TTLs reduce queries but delay changes. Lower the TTL before a planned migration.
Routing policies
| Policy | Answers with | Use |
|---|---|---|
| Simple | One record (possibly several IPs, random order) | Single resource |
| Weighted | Records in proportion to weights (90/10) | Canary releases, gradual migrations, A/B |
| Latency | The region with the lowest measured latency to the user | Multi-region active-active |
| Failover | Primary while healthy, secondary otherwise | Active-passive disaster recovery |
| Geolocation | By user's continent or country | Localised content, legal restrictions |
| Geoproximity | By distance, with adjustable bias | Shifting traffic between regions |
| IP-based | By client CIDR | Route specific ISPs or networks |
| Multivalue | Up to 8 healthy records | Simple client-side load spreading |
Health checks
Route 53 health checkers in multiple locations probe an endpoint (HTTP/HTTPS/TCP), or evaluate a CloudWatch alarm or a combination of other checks. Records tied to a failing check are withdrawn from answers — the basis of DNS failover between regions (Reliability patterns). Remember that clients and resolvers cache answers for the TTL, so failover takes at least that long.
CloudFront
CloudFront is AWS's CDN: hundreds of edge locations that cache content near users and terminate TLS there, plus regional edge caches as a second tier.
Distributions, origins and behaviours
- A distribution has a domain (
d1234.cloudfront.netplus your aliases with an ACM certificate fromus-east-1). - Origins: S3 buckets, ALBs, API Gateway, Lambda function URLs, MediaPackage, or any HTTP server. Origin groups fail over to a secondary origin on errors.
- Cache behaviours map path patterns to origins and settings:
/assets/*→ S3 with long caching,/api/*→ ALB with caching disabled, default → the web app.
Caching
The cache key decides whether two requests share a cached object. By default it's just the URL; adding headers, cookies or query strings to it fragments the cache and lowers the hit ratio — include only what changes the response.
- Cache policies set the cache key and TTLs; origin request policies forward extra values to the origin without adding them to the key.
- Use versioned file names (
app.3f9c2a.js) with long TTLs (Cache-Control: max-age=31536000, immutable) for static assets, so deploys never need invalidations. - Invalidations (
/index.html,/*) remove cached objects early; they're rate-limited and the first 1,000 paths per month are free — useful for HTML, a smell for assets. - Origin Shield adds a central caching layer to protect origins from duplicate misses.
- Even uncacheable dynamic requests benefit: TLS terminates at the edge and travels over AWS's backbone with persistent connections to the origin.
Private S3 origins
Serve S3 content without making the bucket public using Origin Access Control (OAC): CloudFront signs requests to S3, and the bucket policy allows only that distribution.
{
"Effect": "Allow",
"Principal": { "Service": "cloudfront.amazonaws.com" },
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::site-assets-prod/*",
"Condition": { "StringEquals": {
"AWS:SourceArn": "arn:aws:cloudfront::123456789012:distribution/E2ABCDEF123" } }
}For private content per user, use signed URLs or signed cookies with an expiry.
Code at the edge
| CloudFront Functions | Lambda@Edge | |
|---|---|---|
| Runtime | Lightweight JavaScript | Node.js, Python |
| Runs at | Every edge location | Regional edge caches |
| Latency / limits | Sub-millisecond, tiny memory, no network calls | Milliseconds, up to seconds, can call services |
| Use | Header rewrites, redirects, URL normalisation, simple auth checks | Auth with external calls, dynamic origin selection, image transforms |
The key-value store for CloudFront Functions holds small lookups such as redirect tables. Related: Serverless and edge.
Security at the edge
- AWS WAF on CloudFront (or ALB, API Gateway): managed rule groups for the OWASP top 10, known bad inputs and bots; rate-based rules to throttle abusive IPs; geo-blocking (Web security, Rate limiting).
- AWS Shield Standard protects every customer from common network-layer DDoS attacks at no cost; Shield Advanced adds application-layer protection, a response team and cost protection.
- Lock origins down so attackers can't bypass CloudFront: OAC for S3; for ALBs, allow only the CloudFront managed prefix list in the security group and check a secret custom header, or use VPC origins to keep the ALB entirely private.
Global Accelerator
Global Accelerator gives you two static anycast IPs that route users over the AWS backbone to the nearest healthy regional endpoint (ALB, NLB, EC2). Unlike CloudFront it doesn't cache — it accelerates any TCP/UDP traffic and fails over in seconds without DNS TTL delays. Use it for non-HTTP protocols, gaming, VoIP, or when clients need fixed IPs.
QWhy can't you use a CNAME at the zone apex, and how does Route 53 solve it?medium
DNS rules forbid a CNAME from coexisting with other records at the same name, and the zone apex must have SOA and NS records, so example.com can't be a CNAME. Route 53 alias records behave like a CNAME from the operator's point of view but are answered by Route 53 as ordinary A or AAAA records with the target's current IPs, so they work at the apex and track AWS resources like CloudFront distributions and load balancers automatically.
QHow would you serve a static single-page app on AWS?easy
Store the build output in a private S3 bucket, put a CloudFront distribution in front with Origin Access Control so only CloudFront can read the bucket, attach an ACM certificate for the custom domain and point a Route 53 alias record at the distribution. Use hashed asset file names with long cache TTLs and a short TTL (or an invalidation on deploy) for index.html, and configure SPA routing so unknown paths return index.html.
QHow does multi-region failover work with Route 53, and what are its limits?hard
Create failover (or latency) records for each region's endpoint, each associated with a health check that probes a meaningful health endpoint or a CloudWatch alarm. When the primary's check fails, Route 53 stops returning it and answers with the secondary. Limits: resolvers and clients cache answers for the record's TTL and some ignore TTLs, so failover takes at least that long; data must already be replicated to the secondary region; and health checks should reflect real user-facing health. Global Accelerator can fail over faster because clients keep the same anycast IPs.
- Route 53 hosts public and private zones; alias records point apex names at AWS resources for free.
- Routing policies (weighted, latency, failover, geolocation) plus health checks enable canaries and multi-region failover, bounded by DNS caching.
- CloudFront caches at the edge with behaviours per path; keep cache keys minimal and use versioned assets instead of invalidations.
- Serve private S3 content via Origin Access Control and signed URLs; lock origins so the CDN can't be bypassed.
- CloudFront Functions and Lambda@Edge run code at the edge; WAF and Shield defend against attacks.
- Global Accelerator provides static anycast IPs and fast failover for any TCP/UDP traffic.