12.1 — Route 53
Route 53 is AWS’s DNS service. It translates domain names (like api.example.com) to IP addresses or AWS resources. For DevOps, it’s critical for blue-green deployments, failover, and traffic management.
Real-World Analogy
Route 53 is like a phone directory for the internet. When someone dials “api.example.com,” Route 53 looks up the number (IP address) and connects the call. It can also route calls based on the caller’s location, or switch calls to a backup number if the primary is down.
Record Types
| Type |
Purpose |
Example |
| A |
Domain → IPv4 address |
api.example.com → 54.12.34.56 |
| AAAA |
Domain → IPv6 address |
api.example.com → 2001:db8::1 |
| CNAME |
Domain → another domain |
www.example.com → example.com |
| Alias |
Domain → AWS resource (free, zone apex) |
example.com → ALB DNS name |
| MX |
Mail server routing |
example.com → mail.example.com |
| TXT |
Text records (verification, SPF) |
example.com → "v=spf1 ..." |
Creating a Hosted Zone
# Create a public hosted zone
$ aws route53 create-hosted-zone \
--name example.com \
--caller-reference "$(date +%s)"
{
"HostedZone": {
"Id": "/hostedzone/Z1234567890",
"Name": "example.com.",
"ResourceRecordSetCount": 2
},
"DelegationSet": {
"NameServers": [
"ns-1234.awsdns-12.org",
"ns-567.awsdns-34.com",
"ns-890.awsdns-56.co.uk",
"ns-123.awsdns-78.net"
]
}
}
Creating Records
# Create an A record pointing to an EC2 instance
$ aws route53 change-resource-record-sets \
--hosted-zone-id Z1234567890 \
--change-batch '{
"Changes": [{
"Action": "CREATE",
"ResourceRecordSet": {
"Name": "api.example.com",
"Type": "A",
"TTL": 300,
"ResourceRecords": [{"Value": "54.12.34.56"}]
}
}]
}'
# Create an Alias record pointing to an ALB
$ aws route53 change-resource-record-sets \
--hosted-zone-id Z1234567890 \
--change-batch '{
"Changes": [{
"Action": "CREATE",
"ResourceRecordSet": {
"Name": "api.example.com",
"Type": "A",
"AliasTarget": {
"HostedZoneId": "Z35SXDOTRQ7X7K",
"DNSName": "my-alb-123456.ap-south-1.elb.amazonaws.com",
"EvaluateTargetHealth": true
}
}
}]
}'
Routing Policies
| Policy |
Use Case |
How It Works |
| Simple |
Single resource |
Returns one value |
| Weighted |
A/B testing, gradual migration |
90% to v1, 10% to v2 |
| Latency |
Multi-region apps |
Routes to lowest latency region |
| Failover |
Disaster recovery |
Primary → Secondary on health check failure |
| Geolocation |
Compliance, localization |
Route by user’s country/continent |
Weighted Routing (Blue-Green)
# Send 90% to blue (current), 10% to green (new)
$ aws route53 change-resource-record-sets \
--hosted-zone-id Z1234567890 \
--change-batch '{
"Changes": [
{
"Action": "CREATE",
"ResourceRecordSet": {
"Name": "api.example.com",
"Type": "A",
"SetIdentifier": "blue",
"Weight": 90,
"AliasTarget": {
"HostedZoneId": "Z35SXDOTRQ7X7K",
"DNSName": "blue-alb.ap-south-1.elb.amazonaws.com",
"EvaluateTargetHealth": true
}
}
},
{
"Action": "CREATE",
"ResourceRecordSet": {
"Name": "api.example.com",
"Type": "A",
"SetIdentifier": "green",
"Weight": 10,
"AliasTarget": {
"HostedZoneId": "Z35SXDOTRQ7X7K",
"DNSName": "green-alb.ap-south-1.elb.amazonaws.com",
"EvaluateTargetHealth": true
}
}
}
]
}'
Health Checks
# Create a health check for your API
$ aws route53 create-health-check \
--caller-reference "$(date +%s)" \
--health-check-config '{
"IPAddress": "54.12.34.56",
"Port": 443,
"Type": "HTTPS",
"ResourcePath": "/health",
"RequestInterval": 30,
"FailureThreshold": 3
}'
Common Mistakes
| Mistake |
Why It Hurts |
Fix |
| Using CNAME at zone apex |
DNS spec doesn’t allow it |
Use Alias records (free, works at apex) |
| High TTL during migration |
Slow failover, stale DNS |
Lower TTL to 60s before changes, raise after |
| No health checks on failover records |
Failover doesn’t work |
Always attach health checks to failover records |
| Forgetting to update name servers at registrar |
Domain doesn’t resolve |
Copy NS records from Route 53 to your registrar |
Quick Reference
| Task |
Command |
| Create hosted zone |
aws route53 create-hosted-zone --name DOMAIN --caller-reference REF |
| Create/update record |
aws route53 change-resource-record-sets --hosted-zone-id ID --change-batch '...' |
| List records |
aws route53 list-resource-record-sets --hosted-zone-id ID |
| Create health check |
aws route53 create-health-check --caller-reference REF --health-check-config '...' |
| Test DNS resolution |
dig api.example.com or nslookup api.example.com |
Next → CloudFront