Skip to content
Kuza Ndoto Academy

Route 53 & CloudFront

Beginner → IntermediateChapter 5 · Page 20 of 304 min readUpdated 15 Nov 2026

Users type a name such as shop.example.com, not an IP address, and they expect pages to load quickly wherever they are. Amazon Route 53 is AWS's DNS service that turns names into addresses, and Amazon CloudFront is its content delivery network (CDN) that serves your content from locations close to users.

DNS in a nutshell

The Domain Name System is the internet's phone book. When a browser needs shop.example.com, a DNS resolver (often run by your internet provider) asks the root servers, then the .com servers, then the domain's own authoritative name servers, which return the answer. Answers are cached for a time set by each record's TTL (time to live), in seconds.

Route 53

Route 53 does three jobs:

  1. Domain registration: buy domains such as .com or .org. Country domains like .co.ke or .co.ug are usually bought from a local registrar; you can still point them at Route 53 by changing their name servers.
  2. DNS hosting: a hosted zone holds the records for one domain. Public hosted zones answer the internet; private hosted zones answer only inside your VPCs.
  3. Health checks: Route 53 can test an endpoint regularly and stop sending users to it if it fails.
Record typePoints a name toExample
A / AAAAAn IPv4 / IPv6 addressapi.example.com → 203.0.113.10
CNAMEAnother name (not allowed at the domain apex)www.example.com → d111111abcdef8.cloudfront.net
Alias (Route 53 feature)An AWS resource, even at the apexexample.com → CloudFront distribution or load balancer
MXMail servers for the domainEmail for @example.com
TXTFree text, often for verificationDomain ownership checks, email security (SPF)
NSThe zone's name serversCreated automatically with the hosted zone

Prefer alias records when pointing at AWS resources: they follow the resource's changing IP addresses automatically, work at the bare domain, and alias queries to AWS resources such as CloudFront and load balancers are not charged.

You can check what DNS returns with dig (macOS/Linux) or nslookup. For a CNAME that points to CloudFront, the output looks like this example:

dig +short www.example.com
d111111abcdef8.cloudfront.net. 203.0.113.21 203.0.113.47 203.0.113.88 203.0.113.112

Routing policies

PolicyBehaviourUse case
SimpleReturns the record's value(s)One website
WeightedSplits traffic by percentagesSending 10% of users to a new version
LatencySends users to the Region with the lowest latency for themAn app deployed in Cape Town and Ireland
FailoverUses a secondary when the primary's health check failsDisaster recovery site
GeolocationAnswers based on the user's country or continentRegion-specific content or legal requirements

CloudFront

A CloudFront distribution sits in front of one or more origins: an S3 bucket, a load balancer, an API or any web server. Users connect to the nearest edge location. If the edge has a fresh cached copy (a cache hit), it responds immediately; otherwise (a cache miss) it fetches from the origin, returns it and keeps a copy for the next user.

Benefits:

  • Speed: images, CSS and JavaScript come from a nearby edge instead of a distant Region. CloudFront has edge locations in several African cities.
  • Lower origin load: your servers handle only cache misses and dynamic requests.
  • HTTPS: free public certificates from AWS Certificate Manager (issued in us-east-1 for CloudFront).
  • Protection: AWS Shield Standard defends against common network attacks at no extra charge, and you can attach AWS WAF rules to block malicious requests.

Cache behaviours

A distribution can treat paths differently. For a Nairobi e-commerce shop:

Path patternOriginCaching
/static/*, /images/*S3 bucketCache for a long time (days)
/api/*Application Load BalancerDo not cache; forward headers, cookies and query strings
Default (*)Application Load BalancerShort or no caching for HTML pages

How long objects stay cached depends on the cache policy and on Cache-Control headers sent by your origin, for example Cache-Control: max-age=86400 for one day. When you must replace cached content early, create an invalidation:

aws cloudfront create-invalidation --distribution-id E1ABCDEFGHIJKL \
    --paths "/index.html" "/images/banner.jpg"

For private content, such as paid course videos, use CloudFront signed URLs or signed cookies. For small bits of logic at the edge (redirects, header changes), use CloudFront Functions or Lambda@Edge.

Common mistake

Caching personalised pages. If an origin returns a logged-in user's account page and CloudFront caches it, the next visitor may see someone else's details. Never cache responses that depend on cookies or authorisation headers unless your cache key includes them, and send Cache-Control: private, no-store from such pages.

Costs

Route 53 charges a monthly fee per hosted zone, per million standard queries and per health check; domains have yearly registration fees. CloudFront charges mainly for data transferred out to users and for requests, with rates that vary by geographic area; check the official pricing pages. Data transfer from AWS origins to CloudFront is not charged, so serving through CloudFront is often cheaper than serving the same traffic straight from S3 or EC2.

Key points

  • Route 53 registers domains, hosts DNS records in hosted zones and runs health checks.
  • Use alias records to point names (including the bare domain) at AWS resources.
  • Routing policies (weighted, latency, failover, geolocation) control which answer users get.
  • CloudFront caches content at edge locations, adds HTTPS and protection, and reduces origin load.
  • Use cache behaviours per path, and never cache personalised responses.
Up next · New chapter: AI & ML on AWSAWS AI ServicesReady-made AI: Rekognition, Comprehend, Transcribe, Polly, Translate and Textract.
→

Tip: use the ← and → keys to move between pages.