Tuần 4 - Ngày 6: Amazon Route 53
Mục tiêu học tập
- Hiểu Route 53 là gì: DNS, registrar, health check
- Phân biệt các record types (A, AAAA, CNAME, ALIAS)
- Nắm 7 routing policies
- Biết health check và failover
1. Tổng quan Route 53
Amazon Route 53 = scalable DNS service + domain registrar + health check.
Đặc điểm
- Authoritative DNS (managed by AWS)
- 100% availability SLA (only AWS service với 100% SLA)
- Global service (anycast routing)
- Domain registrar (mua/transfer domain)
- Health check + DNS failover
Tên "Route 53"
- Cổng 53 = DNS standard port
2. DNS Concepts ôn nhanh
Hierarchy DNS
DNS Record Types
| Type | Purpose | Example |
|---|---|---|
| A | IPv4 address | example.com → 1.2.3.4 |
| AAAA | IPv6 address | example.com → 2001:db8::1 |
| CNAME | Alias to another DNS name | www.example.com → example.com |
| MX | Mail exchange | example.com → 10 mail.example.com |
| TXT | Text data (SPF, DKIM, verification) | example.com → "v=spf1 ..." |
| NS | Name server | example.com → ns-123.awsdns-12.com |
| SOA | Start of authority | (metadata for zone) |
| PTR | Reverse DNS (IP → name) | (rarely used in R53) |
| SRV | Service record | (port + hostname) |
| CAA | Certificate authority authorization | (SSL cert issuance control) |
| ALIAS | AWS-only: alias to AWS resource | example.com → ALIAS to ALB |
CNAME vs ALIAS
| CNAME | ALIAS | |
|---|---|---|
| Where | DNS standard | Route 53 specific |
| Apex domain (example.com) | KHÔNG được | Được ✓ |
| Subdomain (www.example.com) | OK | OK |
| Target | Bất kỳ DNS name | AWS resources only |
| Cost | DNS query charge | Free queries |
ALIAS targets
- ALB, NLB, CLB
- CloudFront distribution
- API Gateway
- Elastic Beanstalk environment
- S3 website endpoint
- VPC Interface Endpoint
- Global Accelerator
- Route 53 record trong cùng hosted zone
3. Hosted Zones
Định nghĩa
Hosted Zone = container chứa DNS records cho 1 domain.
2 loại
- Public Hosted Zone: resolve qua public internet
- Private Hosted Zone: resolve chỉ trong 1 hoặc nhiều VPC
Cost
- $0.50/month per hosted zone (first 25)
- $0.10/month after 25
Setup public zone
- Tạo hosted zone cho
example.com - Route 53 assign 4 nameservers (ns-1234.awsdns-12.com...)
- Update nameservers ở domain registrar (nếu mua ngoài AWS)
- Add records (A, AAAA, MX, ...)
Setup private zone
- Tạo private hosted zone, associate với VPC
- Records chỉ resolve trong VPC đó
- Use case: internal DNS (db.internal, api.internal)
4. Domain Registrar
Route 53 as Registrar
- Mua domain trực tiếp trong Route 53
- Auto-create hosted zone
- Auto-renew (configurable)
- Domain transfer in/out
Nếu domain mua ngoài (GoDaddy, Namecheap...)
- Tạo hosted zone trong R53
- Lấy 4 nameservers R53 cấp
- Update nameservers ở registrar (GoDaddy, ...)
- Wait DNS propagation (24-48h)
5. 7 Routing Policies
5.1 Simple Routing
- 1 record, 1 hoặc nhiều values (random select)
- Không health check
- Default
example.com → A → 1.2.3.4
→ 1.2.3.5 (random pick)
5.2 Weighted Routing
- Split traffic theo % weight
- Tổng weights không cần = 100
example.com → A → 1.2.3.4 (weight 70)
→ 1.2.3.5 (weight 30)
→ 70% traffic đến .4, 30% đến .5
Use case
- A/B testing
- Gradual rollout (canary)
- Multi-region traffic distribution by ratio
5.3 Latency-based Routing
- Route user đến Region với lowest latency từ vị trí user
- AWS đo latency real-time
Use case
- Global app multi-region
- Optimize user experience
5.4 Failover Routing
- Active-Passive failover
- Primary record + Secondary record
- Health check trên primary → if unhealthy, route to secondary
Primary : ALB-region-A (healthy)
Secondary: S3 static site (passive)
If ALB unhealthy → traffic to S3 maintenance page
Use case
- DR
- Active-passive HA
5.5 Geolocation Routing
- Route theo vị trí địa lý của user (country, continent, default)
- Khác latency-based: dựa vào vị trí, không phải latency
Use case
- Localized content (Vietnamese website cho VN users)
- Compliance (data residency)
- Restrict access by geography
5.6 Geoproximity Routing (Traffic Flow only)
- Route dựa vào địa lý + bias
- Bias (-99 to +99) để adjust traffic về region
- Yêu cầu Route 53 Traffic Flow (UI tool)
Bias = 0 : balance evenly by geography
Bias = +50 : pull more traffic to this region
Bias = -50 : push traffic away
5.7 Multivalue Answer Routing
- Return multiple records (up to 8) trong 1 response
- Client (browser) tự pick 1 random
- Optional health check per record
- Lightweight load balancing alternative
example.com → A → 1.2.3.4 (healthy)
→ 1.2.3.5 (healthy)
→ 1.2.3.6 (unhealthy — skip)
Comparison Table
| Policy | Use case | Health check |
|---|---|---|
| Simple | Single resource | No |
| Weighted | Split % | Optional |
| Latency-based | Global app, minimize latency | Optional |
| Failover | Active-passive HA | Required for primary |
| Geolocation | Localized content | Optional |
| Geoproximity | Bias-based geographic | Optional |
| Multivalue | Lightweight LB | Optional |
6. Health Checks
3 loại
Endpoint health check
- Monitor HTTP/HTTPS/TCP endpoint
- Custom path, port, interval (10s or 30s), failure threshold (3 default)
- ~15 global locations ping endpoint
Calculated health check
- Combine multiple child health checks với AND/OR/NOT
- Use case: "App healthy if 3+ regions healthy"
CloudWatch alarm health check
- Trigger health check based on CloudWatch alarm state
- Use case: alarm khi DynamoDB throttling → DNS failover
Cost
- Endpoint within AWS: free (basic), $1/check optional features
- Endpoint outside AWS: $0.75/check
- Calculated: $1/check
- CW alarm: $1/check
DNS failover with health check
- Add health check ID vào record
- Nếu health check fail → record không được return trong DNS query
- Combine với Failover routing policy cho active-passive
7. Routing Examples
Example 1: Multi-region active-active với failover
Example 2: Blue/Green deployment với weighted
Example 3: Geolocation cho compliance
8. DNS TTL
Định nghĩa
TTL (Time To Live) = thời gian DNS resolver cache record (seconds).
Trade-off
- High TTL (24 hours): Less DNS query cost, slower propagation when change
- Low TTL (60 sec): Fast propagation, more query cost
Best practice
- Stable record: TTL 1-24 hours
- Frequently changing: TTL 60-300 sec
- ALIAS records: AWS auto-manages TTL (recommended)
- Trước migration: lower TTL 1-2 days trước để propagate fast
9. Route 53 Resolver
Định nghĩa
Route 53 Resolver = managed DNS resolver cho VPC, supports:
- Resolve AWS resources (S3 endpoint, ALB DNS, ...)
- Resolve public domains
- Inbound endpoint: on-prem query AWS DNS
- Outbound endpoint: AWS query on-prem DNS
Hybrid DNS
Use case
- Hybrid: AWS resolve on-prem domains
- On-prem resolve AWS private hosted zone
10. DNSSEC
Định nghĩa
DNSSEC (DNS Security Extensions) = sign DNS responses để prevent DNS spoofing.
Route 53 supports
- Sign hosted zone: enable DNSSEC, R53 manage KSK (Key Signing Key) trong KMS
- Validate (Resolver feature)
Use case
- Government, regulated industries
- High-security domains
Câu hỏi ôn tập
-
Khác biệt CNAME và ALIAS? Apex domain dùng được không?
Xem đáp án
CNAME: DNS standard, map hostname → hostname khác, không dùng được ở apex domain (root domain
example.com). Tính phí query. ALIAS: Route 53 extension, map hostname → AWS resource (ALB, CloudFront, S3 website, API GW, Elastic Beanstalk), dùng được ở apex domain, không tính phí query riêng, hỗ trợ health check. Luôn dùng ALIAS thay CNAME khi target là AWS service. -
Latency-based và Geolocation routing khác nhau như thế nào?
Xem đáp án
Latency-based: Route 53 đo latency từ user đến từng AWS Region và route đến Region có latency thấp nhất. User ở Vietnam có thể được route đến Tokyo nếu đó là fastest. Geolocation: route dựa trên địa lý vật lý của user (country, continent) — user từ Vietnam luôn đến server cụ thể bất kể latency. Dùng Geolocation cho compliance (data residency), localization; Latency cho performance tốt nhất.
-
Failover routing yêu cầu gì cho primary record?
Xem đáp án
Primary record phải có Health Check được associate. Route 53 monitor endpoint qua health check — khi primary fail (health check fail), tự động failover sang secondary record. Secondary record không cần health check (nhưng best practice là có). Health check có thể monitor HTTP/HTTPS endpoints, TCP ports, hoặc CloudWatch alarms.
-
Multivalue Answer routing return tối đa mấy records?
Xem đáp án
8 records (tối đa). Multivalue Answer trả về nhiều IP addresses cho cùng hostname, chỉ trả về records healthy (cần health check per record). Khác Simple routing: Simple không có health check filtering. Không thay thế được Load Balancer (DNS round-robin không perfect), nhưng là giải pháp đơn giản cho distributed/multi-region không cần ALB.
-
Route 53 Resolver Inbound Endpoint dùng để làm gì?
Xem đáp án
Cho phép on-premises DNS servers forward DNS queries đến Route 53 Resolver (để resolve AWS internal hostnames như VPC private zones, RDS endpoints). Inbound Endpoint tạo ENIs trong VPC — on-premises DNS queries đến ENI IPs, Route 53 resolve và trả kết quả. Ngược lại, Outbound Endpoint forward DNS queries từ VPC ra on-premises DNS servers.
Bài tập thực hành
- Tạo Public Hosted Zone cho domain (có thể dùng domain free .tk hoặc subdomain)
- Add A record với Simple routing trỏ về 1 EC2
- Tạo Weighted routing: 80/20 split cho A/B testing
- Setup Failover routing với health check trên ALB
- Tạo Private Hosted Zone, associate với VPC, test resolve internal name
- Setup Route 53 Resolver Inbound endpoint (advanced)
Tài liệu tham khảo chính thức
Tiếp theo: Quiz Tuần 4