</>Học Dev
Bài học

Tuần 4 - Ngày 6: Amazon Route 53

Tuần 4 – Ngày 6

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

.(Root).com(TLD-TopLevelDomain).org.net(others)example.com(Domain)www.example.com(Subdomain)api.example.commail.example.com

DNS Record Types

TypePurposeExample
AIPv4 addressexample.com → 1.2.3.4
AAAAIPv6 addressexample.com → 2001:db8::1
CNAMEAlias to another DNS namewww.example.com → example.com
MXMail exchangeexample.com → 10 mail.example.com
TXTText data (SPF, DKIM, verification)example.com → "v=spf1 ..."
NSName serverexample.com → ns-123.awsdns-12.com
SOAStart of authority(metadata for zone)
PTRReverse DNS (IP → name)(rarely used in R53)
SRVService record(port + hostname)
CAACertificate authority authorization(SSL cert issuance control)
ALIASAWS-only: alias to AWS resourceexample.com → ALIAS to ALB

CNAME vs ALIAS

CNAMEALIAS
WhereDNS standardRoute 53 specific
Apex domain (example.com)KHÔNG đượcĐược
Subdomain (www.example.com)OKOK
TargetBất kỳ DNS nameAWS resources only
CostDNS query chargeFree 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

  1. Tạo hosted zone cho example.com
  2. Route 53 assign 4 nameservers (ns-1234.awsdns-12.com...)
  3. Update nameservers ở domain registrar (nếu mua ngoài AWS)
  4. Add records (A, AAAA, MX, ...)

Setup private zone

  1. Tạo private hosted zone, associate với VPC
  2. Records chỉ resolve trong VPC đó
  3. 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...)

  1. Tạo hosted zone trong R53
  2. Lấy 4 nameservers R53 cấp
  3. Update nameservers ở registrar (GoDaddy, ...)
  4. 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
example.com:Recordus-east-1ALB-us-eastRecordap-southeast-1ALB-ap-southeastUserVNLatencythpnhtđếnap-southeast-1ALB-ap-southeastUserUSLatencythpnhtđếnus-east-1ALB-us-east

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
example.com:Country=VNALBVietnamCountry=JPALBJapanContinent=NAALBUSDefaultALBglobal

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

PolicyUse caseHealth check
SimpleSingle resourceNo
WeightedSplit %Optional
Latency-basedGlobal app, minimize latencyOptional
FailoverActive-passive HARequired for primary
GeolocationLocalized contentOptional
GeoproximityBias-based geographicOptional
MultivalueLightweight LBOptional

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.com(Latency-based):LatencyrecordA(us-east-1)+HealthcheckonALB-us-eastLatencyrecordB(eu-west-1)+HealthcheckonALB-eu-westIfALB-us-eastdown:R53khôngreturnrecordATtcusersroutetoALB-eu-west(vnclosestlatencywise)

Example 2: Blue/Green deployment với weighted

example.com:Blue:95%weight(production)Green:5%weight(canarynewversion)TeststableincreaseGreenweightgradually100%

Example 3: Geolocation cho compliance

api.example.com:EUcountriesALB-eu-west(GDPR-compliant)USALB-us-eastDefaultALB-global(withPIIstripping)

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

On-premDNSInboundResolverEndpointVPC(query*.internal)Resolvesinternal.example.com(AWS)VPCOutboundResolverEndpointOn-premDNS(forwardquery)Forwardingrules:corp.example.comon-premDNS

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

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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