Beginner · Networking and databases: VPC and RDS · topic 18 of 50 · 30 min
DNS and CDN: Route 53 and CloudFront
Explanation
Why DNS and a CDN matter
Users type a name, not an IP address. DNS (Domain Name System) is the internet's phone book that turns that name into an address. A CDN (Content Delivery Network) keeps copies of your files in many cities, so a user in Guwahati gets a video from a nearby edge server instead of from a data centre in Mumbai. Together they decide how fast, and how reliably, users reach your app.
Route 53 basics
Amazon Route 53 can register domain names and answer DNS queries. A hosted zone holds the records for one domain, such as example.com. A record maps a name to a value and has a TTL (time to live): how many seconds resolvers may cache the answer.
| Record | Points to | Example |
|---|---|---|
| A | An IPv4 address | www → 203.0.113.10 |
| AAAA | An IPv6 address | www → 2001:db8::10 |
| CNAME | Another name (not allowed at the zone apex) | blog → myblog.example.net |
| Alias (Route 53 only) | An AWS resource such as CloudFront, a load balancer or an S3 website | example.com → d111111abcdef8.cloudfront.net |
| MX, TXT | Mail servers; verification text | Email and domain ownership checks |
The zone apex is the bare domain, example.com, without www. Standard DNS does not allow a CNAME there. Route 53 alias records solve this: they work at the apex, follow the AWS resource's changing IPs automatically, and queries to AWS resources through alias records are not charged.
Routing policies and health checks
- Simple: one answer (or several values returned together).
- Weighted: split traffic by weights, for example 90 to the current version and 10 to a new one (a canary release).
- Latency: send each user to the region with the lowest latency for them.
- Failover: send traffic to the primary while its health check passes, and to a standby when it fails.
- Geolocation: answer by the user's country or continent, for example to meet data rules or show local content.
- Also available: geoproximity, multivalue answer and IP-based routing.
A health check regularly calls an endpoint, such as https://api.example.com/healthz, from several locations. Failover and other policies skip records whose health check is failing.
{
"Changes": [
{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "api.example.com",
"Type": "A",
"SetIdentifier": "v2-canary",
"Weight": 10,
"TTL": 60,
"ResourceRecords": [{ "Value": "203.0.113.20" }]
}
}
]
}CloudFront: caching at the edge
Amazon CloudFront is AWS's CDN. You create a distribution with one or more origins, the places where the real content lives: an S3 bucket (made private with Origin Access Control), an Application Load Balancer, or any HTTP server. Users connect to the nearest edge location. On a cache hit, the edge already has the file and returns it at once. On a cache miss, it fetches from the origin, returns it, and keeps a copy for next time.
How long a copy stays is controlled by TTLs in the cache policy and by Cache-Control headers from your origin. Long TTLs give more hits and lower origin load; short TTLs give fresher content. The usual trick is versioned file names (app.3f9c2a.js) with long TTLs, plus short TTLs for HTML. To remove an object early, create an invalidation.
aws cloudfront create-invalidation --distribution-id EDFDVBD6EXAMPLE --paths "/index.html" "/live/*"HTTPS with your own domain
Use a free public certificate from AWS Certificate Manager (ACM). For CloudFront, the certificate must be requested or imported in the US East (N. Virginia) region, us-east-1, whatever region your origin is in. A load balancer in Mumbai, by contrast, needs its certificate in ap-south-1. CloudFront also integrates with AWS WAF for filtering attacks and includes AWS Shield Standard DDoS protection.
Need help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
DNS and CDN: Route 53 and CloudFront · 1/7
DNS turns names into addresses. A CDN keeps copies of your content close to users. Together they make apps fast and reliable.
Prefer a video by a teacher? Find free videos on “aws route 53 routing policies alias record cloudfront cdn tutorial” on YouTube ↗
In real life: An Indian news site on election results day
On counting day a Hindi news channel's website gets ten times its normal traffic, with live video and constantly updated results pages. Video is packaged into small HLS segments stored in S3; CloudFront edges in cities across India cache each segment, so millions of viewers are served from the edge and the origin sees only a small fraction of requests. The live playlist file has a TTL of a few seconds; segments and images have long TTLs. Route 53 uses an alias record at the apex to point at CloudFront, and a failover record sends API traffic to a standby region if the health check on the primary fails.
Practice (0/3 done)
You want example.com (with no www) to point at a CloudFront distribution. Which Route 53 record type do you use?
Write hit_ratio(hits, misses) that returns the cache hit ratio as a percentage rounded to 1 decimal place. If there were no requests at all, return 0.0. Example: hit_ratio(950, 50) returns 95.0.
Simulate Route 53 weighted routing. records is a list of (name, weight) pairs. Write pick_record(records, r) where r is a whole number from 0 to total weight minus 1: walk the records adding up weights and return the first name whose running total is greater than r. Also write shares(records) that returns a dict of name to the percentage of traffic it gets, rounded to 1 decimal place.
Quick quiz
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- Managed relational databases: RDS and AuroraNetworking and databases: VPC and RDS · same module
- VPC security and connectivityNetworking and databases: VPC and RDS · same module
- DNS: names to addressesComputer Networking (CCNA level) · IP services: DHCP, DNS, NAT and more
- Scaling: handling more usersBackend Development · Deployment and scaling
- Portfolio projects that get interviewsCertifications and cloud careers
- DNS: the internet's phone bookCyber Security: from zero to SOC analyst · Networking for security
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
Which routing policy sends 10 percent of users to a new version for testing?
Answer: Weighted
Weighted routing splits traffic by the weights you set, such as 90 and 10.
In which region must an ACM certificate be for a CloudFront distribution?
Answer: us-east-1
CloudFront uses certificates from ACM in US East (N. Virginia), us-east-1.
A user requests a file that the nearest edge location does not have. What happens?
Answer: The edge fetches it from the origin, returns it and caches it
That is a cache miss: the edge gets the object from the origin and keeps a copy for later requests.
You will move a website to new servers tomorrow. What should you do today with its DNS record?
Answer: Lower the TTL, for example to 60 seconds
A short TTL makes resolvers pick up the new address quickly after the change.
Which routing policy answers based on the country of the user?
Answer: Geolocation
Geolocation routing chooses the answer by the user's location, such as country or continent.
Which record tells other mail servers where to deliver email for a domain?Related
Answer: MX
MX records name the mail servers; the lowest preference number is tried first.
What are edge locations mainly used for?Related
Answer: Caching content close to users through a CDN
Edge locations (points of presence) serve cached content near users.
Why is CloudFront preferred over the S3 website endpoint for a public site?Related
Answer: CloudFront gives HTTPS, caching and lets the bucket stay private
The website endpoint is HTTP only and needs public read. CloudFront with OAC keeps the bucket private and adds HTTPS and caching.
What does a CDN do?Related
Answer: Serves static files like images from servers near the user
A CDN keeps copies of static files in many cities, so they load fast and your server does less work.
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- This is the last topic of “Networking and databases: VPC and RDS”. The module exam comes next.
- Module 4 exam: Networking and databases, VPC and RDS · 14 questions · 25 min, without help. 5 topics of this module still to finish first.
- Then the next module, Serverless, monitoring and cost control. 50 topics left in the course before the final exam.
← Previous: Choosing a database: DynamoDB, caches and warehouses