Route 53 & CloudFront
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:
- Domain registration: buy domains such as
.comor.org. Country domains like.co.keor.co.ugare usually bought from a local registrar; you can still point them at Route 53 by changing their name servers. - 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.
- Health checks: Route 53 can test an endpoint regularly and stop sending users to it if it fails.
| Record type | Points a name to | Example |
|---|---|---|
| A / AAAA | An IPv4 / IPv6 address | api.example.com → 203.0.113.10 |
| CNAME | Another name (not allowed at the domain apex) | www.example.com → d111111abcdef8.cloudfront.net |
| Alias (Route 53 feature) | An AWS resource, even at the apex | example.com → CloudFront distribution or load balancer |
| MX | Mail servers for the domain | Email for @example.com |
| TXT | Free text, often for verification | Domain ownership checks, email security (SPF) |
| NS | The zone's name servers | Created 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
Routing policies
| Policy | Behaviour | Use case |
|---|---|---|
| Simple | Returns the record's value(s) | One website |
| Weighted | Splits traffic by percentages | Sending 10% of users to a new version |
| Latency | Sends users to the Region with the lowest latency for them | An app deployed in Cape Town and Ireland |
| Failover | Uses a secondary when the primary's health check fails | Disaster recovery site |
| Geolocation | Answers based on the user's country or continent | Region-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 pattern | Origin | Caching |
|---|---|---|
/static/*, /images/* | S3 bucket | Cache for a long time (days) |
/api/* | Application Load Balancer | Do not cache; forward headers, cookies and query strings |
Default (*) | Application Load Balancer | Short 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.
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.
Tip: use the ← and → keys to move between pages.
