devHọc Dev
EN
Bài học

Tuần 2 - Ngày 2: VPC Endpoints, VPN/Direct Connect và Route 53

Tuần 2 – Ngày 2

Bài này gộp 3 chủ đề: VPC Endpoints và PrivateLink, VPN và Direct Connect Intro, Amazon Route 53.

Mục tiêu học tập

  • Phân biệt Gateway Endpoint và Interface Endpoint
  • Hiểu PrivateLink cho 3rd-party services
  • Nắm endpoint policy
  • Biết khi nào dùng VPC Endpoint vs NAT Gateway
  • Hiểu Site-to-Site VPN architecture
  • Phân biệt VPN, Direct Connect, Client VPN
  • Nắm bandwidth, latency trade-offs
  • Biết khi nào dùng cái nào cho hybrid connectivity
  • 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 VPC Endpoint

Vấn đề

Khi EC2 trong private subnet muốn access AWS services (S3, DynamoDB, SQS, KMS...):

  • Cách cũ: route 0.0.0.0/0 → NAT GW → IGW → AWS service public endpoint
  • Vấn đề: traffic đi qua internet → cost (NAT GW data processing), security concern

Giải pháp: VPC Endpoint

  • Private connection từ VPC đến AWS services
  • Traffic KHÔNG qua internet
  • Reduce NAT GW cost, improve security

3 loại endpoints

LoạiServicesCostSetup
Gateway EndpointS3, DynamoDBFreeRoute table entry
Interface Endpoint (PrivateLink)Hầu hết AWS services$0.01/hour + $0.01/GBENI trong subnet
Gateway Load Balancer EndpointCho appliance$/hourĐặc biệt cho firewall

2. Gateway Endpoint

Đặc điểm

  • Chỉ cho S3 và DynamoDB
  • Free (no extra charge)
  • Triển khai dạng route table entry (target = vpce-xxx)
  • Không tạo ENI, không tốn IP
  • Chỉ accessible từ VPC nơi endpoint tồn tại (không cross-VPC)

Setup

  1. Tạo Gateway Endpoint cho S3
  2. Chọn route table(s) liên quan
  3. AWS tự động add route: s3.us-east-1.amazonaws.com prefix list → vpce-xxx

Architecture

PrivateSubnet:EC2───►RouteTable├──10.0.0.0/16→local├──0.0.0.0/0→NATGW└──pl-63a5400a(S3)→vpce-12345(GatewayEndpoint)│▼S3Bucket(quaAWSnetwork)

Endpoint Policy

  • Default: allow all access đến service
  • Custom policy: restrict bucket, action, principal
{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Principal": "*",
    "Action": ["s3:GetObject", "s3:PutObject"],
    "Resource": "arn:aws:s3:::my-bucket/*"
  }]
}

Use case

  • EC2 trong private subnet upload/download S3 (giảm NAT GW cost)
  • Lambda VPC access DynamoDB
  • Compliance: traffic không leave VPC

Đặc điểm

  • Hầu hết AWS services support (100+): SQS, SNS, KMS, Secrets Manager, ECR, ECS, EventBridge, API Gateway, ...
  • Triển khai dạng ENI trong subnet với private IP
  • Truy cập qua DNS (private DNS có thể enable)
  • Cost: $0.01/hour per endpoint per AZ + $0.01/GB data processed
  • Support cross-VPC qua PrivateLink

Setup

  1. Tạo Interface Endpoint cho service (e.g., com.amazonaws.us-east-1.sqs)
  2. Chọn subnet(s) — tạo ENI trong mỗi subnet
  3. Chọn Security Group
  4. Enable Private DNS (recommended) → service URL public tự resolve sang private IP

DNS Resolution

Without Private DNS
SQS public URL: sqs.us-east-1.amazonaws.com
→ Resolves to public IP
→ Need to use endpoint-specific DNS: vpce-xxx.sqs.us-east-1.vpce.amazonaws.com
SQS public URL: sqs.us-east-1.amazonaws.com
→ Resolves to private IP của Interface Endpoint
→ Code không cần đổi

Endpoint Policy

  • Restrict actions, resources, principals
  • Apply per endpoint

Use case

  • Private subnet access SQS, Secrets Manager, KMS
  • Compliance (data không out internet)
  • Reduce NAT GW data processing cost

4. Endpoint Pricing Math Example

Scenario

EC2 trong private subnet pull image từ ECR, mỗi tháng 100 GB.

Option A: NAT Gateway (no endpoint)
  • NAT GW: $0.045/hour × 730 = $32.85/month
  • Data processing: $0.045/GB × 100 GB = $4.50/month
  • Total: ~$37.35/month
Option B: Interface Endpoint cho ECR
  • Endpoint: $0.01/hour × 730 × 1 AZ = $7.30/month
  • Data: $0.01/GB × 100 GB = $1.00/month
  • Total: ~$8.30/month (cần ECR Docker Registry endpoint cũng)

→ Tiết kiệm ~$29/month với endpoint cho 100 GB.

Quy tắc

  • Endpoint rẻ hơn NAT GW khi data lớn (> ~10 GB/month per service)
  • Multi-AZ Interface Endpoint = $0.01/hour × số AZ

Định nghĩa

PrivateLink = expose 1 service trong VPC của bạn để consumer ở VPC khác (cùng/khác account) access qua private network.

2 vai trò

  • Service provider: tạo VPC Endpoint Service từ NLB (or GWLB)
  • Service consumer: tạo Interface Endpoint connect đến service

Architecture

ProviderVPC(AccountA):┌─────────────────────────────────────────┐│EC2/Service│││││▼││NetworkLoadBalancer│││││▼││VPCEndpointService││(servicename:com.amazonaws.vpce.xxx)│└──────────────────┬──────────────────────┘││PrivateLink│ConsumerVPC(AccountB):┌──────────────────▼──────────────────────┐│InterfaceEndpoint││(ENItrongsubnet)││▲│││││EC2(privatesubnet)│└─────────────────────────────────────────┘

Use cases

  • SaaS provider expose API qua PrivateLink
  • Cross-account internal service sharing
  • Partner integration không qua internet

Allowlist

  • Service provider whitelist consumer accounts/principals
  • Consumer cần được approve mới connect được

6. Endpoint Services hỗ trợ Gateway/Interface

Gateway (free) — chỉ 2 services

  • S3
  • DynamoDB

Interface ($) — hầu hết khác

  • API Gateway (PrivateLink)
  • CloudWatch (Logs, Monitoring, Events)
  • SQS, SNS, EventBridge
  • KMS, Secrets Manager, Systems Manager
  • ECR, ECS, EKS
  • STS
  • Lambda (invoke endpoint)
  • DynamoDB cũng có Interface endpoint (mới — chọn 1 trong 2)
  • SageMaker, Bedrock
  • ...

Note: S3 Interface Endpoint

  • AWS đã add Interface Endpoint cho S3 (ngoài Gateway)
  • Khi nào dùng Interface cho S3?
    • Access S3 từ on-prem qua Direct Connect/VPN (Gateway không route được on-prem)
    • Cross-VPC qua Transit Gateway access S3 endpoint share
  • Default: dùng Gateway S3 endpoint (free)

7. Endpoint Policy Examples

Restrict S3 endpoint to specific bucket

{
  "Version": "2012-10-17",
  "Statement": [{
    "Sid": "AllowOnlyMyBucket",
    "Effect": "Allow",
    "Principal": "*",
    "Action": "s3:*",
    "Resource": [
      "arn:aws:s3:::my-bucket",
      "arn:aws:s3:::my-bucket/*"
    ]
  }]
}

Restrict S3 bucket to only my VPC Endpoint (Bucket Policy)

{
  "Version": "2012-10-17",
  "Statement": [{
    "Sid": "DenyExceptMyVPCE",
    "Effect": "Deny",
    "Principal": "*",
    "Action": "s3:*",
    "Resource": [
      "arn:aws:s3:::my-bucket",
      "arn:aws:s3:::my-bucket/*"
    ],
    "Condition": {
      "StringNotEquals": {
        "aws:SourceVpce": "vpce-1234567890abcdef"
      }
    }
  }]
}

→ Bucket chỉ accessible từ VPC này qua endpoint cụ thể.

8. Decision: VPC Endpoint vs NAT Gateway

SituationRecommendation
EC2 private subnet access chỉ S3 + DynamoDBGateway Endpoints (free), no NAT GW needed nếu không có internet access khác
EC2 access multiple AWS services + internetNAT GW + Interface Endpoints cho services có data lớn
Data transfer to S3 > 10 GB/monthGateway Endpoint chắc chắn
Need access 3rd-party SaaS via PrivateLinkPrivateLink Interface Endpoint
Strict compliance: no internetEndpoints cho mọi service + No NAT GW

9. Cost Optimization với Endpoints

Strategies

  1. S3 Gateway Endpoint (luôn dùng — free + giảm NAT cost)
  2. DynamoDB Gateway Endpoint
  3. Interface Endpoints cho services có > 10 GB/month data
  4. Consolidate AZs cho Interface Endpoints (mỗi AZ tăng $0.01/hour)
  5. Endpoint Policy restrict để tránh leak through

Common high-cost services qua NAT

  • ECR image pulls (big images)
  • CloudWatch Logs ingestion
  • S3 large object transfers
  • Secrets Manager / Parameter Store (frequent calls)

Phần 2: VPN và Direct Connect Intro

1. Tổng quan Hybrid Connectivity

Use cases hybrid (on-prem + AWS)

  • Migration (lift-and-shift dần)
  • Data sync giữa on-prem DC và AWS
  • Burst compute lên AWS từ on-prem
  • DR (AWS làm DR cho on-prem)
  • Compliance (data sensitive ở on-prem, app ở AWS)

Options

OptionBandwidthLatencyCostEncryptedSetup time
Site-to-Site VPN~1.25 Gbps/tunnelVariable (internet)$Yes (IPsec)Phút
Direct Connect1, 10, 100 Gbps dedicatedStable, low$$$No (qua DX)Tuần - tháng
DX + VPNSame as DXSame as DX$$$YesTuần
Client VPNPer-userVariable$/user-hourYesPhút
Transit Gateway + DX/VPNAggregateSame$$Tùy—

2. Site-to-Site VPN

Định nghĩa

Site-to-Site VPN = IPsec tunnel giữa on-prem router (Customer Gateway) và AWS Virtual Private Gateway / Transit Gateway.

Components

┌───On-Premises────┐┌───AWSVPC──────┐│││││Customer││Virtual││Gateway(CGW)│◄──IPsec─────►│Private││(on-premrouter)│2tunnels│Gateway(VGW)││PublicIP│││└────────────────────┘└──────────────────┘
Customer Gateway (CGW)
  • Đại diện cho on-prem device trong AWS
  • Public IP của router on-prem (hoặc NAT IP)
  • BGP ASN (nếu dùng dynamic routing)
Virtual Private Gateway (VGW)
  • AWS-side endpoint
  • Attached vào VPC
  • HA built-in (2 endpoints)

2 VPN Tunnels per Connection

  • Mỗi VPN connection có 2 tunnels ở 2 AZ khác nhau (HA)
  • On-prem router config cả 2 tunnels (active-active hoặc active-passive)

Routing options

  • Static routing: manual add routes
  • Dynamic routing (BGP): AWS và CGW exchange routes qua BGP

Bandwidth

  • Per tunnel: ~1.25 Gbps (single TCP flow)
  • Multi-tunnel ECMP: lên 5 Gbps total (Transit Gateway VPN attachment)
  • Đủ cho hầu hết workloads, không phù hợp high-volume data transfer

Setup time

  • Phút để setup AWS side
  • Phụ thuộc on-prem router config (thường vài giờ)

Cost

  • $0.05/hour per VPN connection
  • Data transfer out (AWS → on-prem): tính theo giá internet egress chuẩn (~$0.09/GB) — VPN không có mức giá riêng

Use case

  • Quick hybrid setup
  • DR connection (backup cho DX)
  • Lower bandwidth needs (< 1 Gbps)

3. AWS Direct Connect (DX)

Định nghĩa

Direct Connect = dedicated physical fiber connection từ on-prem đến AWS, không qua internet.

Đặc điểm

  • Dedicated bandwidth: 1, 10, 100 Gbps
  • Lower latency: predictable, ổn định (không qua internet)
  • Lower data transfer cost (chargeable to "DX rates")
  • Setup time: tuần - tháng (cần install physical fiber)
  • Không encrypted by default (cần VPN over DX để encrypt)

Setup

  1. Order DX connection từ AWS Console
  2. Connect on-prem router → DX location (1 trong 100+ DX POPs toàn cầu)
  3. Hoặc dùng DX Partner (AT&T, Verizon, ...) nếu không có physical presence tại DX POP
  4. Configure Virtual Interface (VIF)

3 loại Virtual Interface (VIF)

VIF TypeUse case
Private VIFAccess VPC qua VGW (private resources)
Public VIFAccess AWS public services (S3, DynamoDB) qua DX
Transit VIFAccess multiple VPCs qua Transit Gateway

Direct Connect Gateway

  • Cho phép 1 DX connection access multiple VPCs ở multiple Regions (cùng account hoặc cross-account)
  • Topology: CGW → DX → DX Gateway → VGW (multiple VPCs)

HA cho Direct Connect

  • Single DX connection: NOT HA (single physical link)
  • Best practice:
    • 2 DX connections ở 2 DX locations khác nhau (max HA)
    • Hoặc 1 DX + VPN backup (cost optimization)

Cost

  • Port hour: $/hour per Gbps port (~$0.30/hour cho 1 Gbps)
  • Data transfer out: rẻ hơn internet egress (~$0.02/GB vs $0.09/GB)
  • Data transfer in: free

Use case

  • High-volume data transfer (TB/day)
  • Latency-sensitive apps (financial trading, real-time)
  • Compliance (regulated industries)
  • Predictable network performance

4. VPN over Direct Connect (Encrypted DX)

Pattern

  • DX provides bandwidth + low latency
  • VPN over DX adds encryption (IPsec)

Use case

  • HIPAA, PCI-DSS compliance requires encryption in-transit
  • Untrusted DX provider (rare)

5. AWS Client VPN

Định nghĩa

Client VPN = managed VPN service cho individual user devices (laptop, mobile) connect vào AWS VPC qua OpenVPN client.

Đặc điểm

  • TLS-based (OpenVPN)
  • Authentication:
    • Active Directory (qua AWS Directory Service)
    • Federated SAML (IdP)
    • Mutual TLS certificates
  • Authorization: per-user, per-network
  • Multi-platform clients: Windows, macOS, Linux

Architecture

UserLaptop──OpenVPN──►ClientVPNEndpoint──►VPC(remoteworker)(intargetsubnet)▲│Optional:peerVPC,on-prem

Use case

  • Remote employees access internal apps (alternative to corporate VPN)
  • Contractor access cụ thể VPCs
  • BYOD scenarios

Cost

  • $0.10/hour per association (endpoint to subnet)
  • $0.05/hour per active user connection

6. AWS Direct Connect Resiliency Models

AWS đề xuất 3 resilience patterns:

Maximum Resiliency (4 nines+)

  • 2 DX locations, each with 2 connections (4 total)
  • Tolerate location failure + connection failure
  • Cost cao nhất

High Resiliency (3 nines+)

  • 2 DX locations, 1 connection each (2 total)
  • Tolerate location failure
  • Cost vừa

Development & Test

  • 1 DX location, 1 connection
  • NOT HA — chấp nhận downtime nếu DX fail
    • Backup VPN
  • Cost thấp

7. AWS Global Accelerator vs DX

Direct ConnectGlobal Accelerator
Use caseOn-prem ↔ AWS hybridEnd-user → AWS app
ConnectionDedicated fiberAnycast IPs over internet (+ AWS backbone)
EncryptedNo (use VPN over)TLS-terminated at edge
Static IPN/AYes (2 anycast)

8. Hybrid Network Architecture Patterns

Pattern 1: Simple Site-to-Site VPN

On-premDC──IPsecVPN──VGW──VPC
  • Quick start
  • Cost-effective
  • Adequate < 1 Gbps

Pattern 2: Direct Connect + VPN Backup

On-premDC───DX────VGW──VPC└──VPNbackup─┘
  • HA: DX primary, VPN failover
  • Lower cost than 2 DX

Pattern 3: DX + Transit Gateway (multiple VPCs)

On-prem──DX──DXGateway──TransitGateway──VPC1,VPC2,VPC3...
  • Single connection access nhiều VPCs
  • Scalable

Pattern 4: Multi-Region DX

On-prem──DX(us-east-1)──DXG──TGWUS──VPCsUS└──DX(eu-west-1)──DXG──TGWEU──VPCsEU
  • Global presence
  • Region-specific connectivity

9. Network Performance Considerations

Latency

  • VPN over internet: ~50-100ms (variable)
  • DX from US East coast → us-east-1: ~5-10ms
  • Cross-Region: 50-200ms (depending)

Bandwidth

  • VPN: ~1.25 Gbps/tunnel
  • DX: 1, 10, 100 Gbps dedicated
  • VPC-to-VPC peering: no limit (within Region)

Data Transfer Pricing

  • AWS → Internet: $0.09/GB (us-east-1 base)
  • AWS → DX: $0.02-0.03/GB (cheaper!)
  • AWS → VPN: theo giá internet egress (~$0.09/GB) — Site-to-Site VPN không có mức riêng; DX là cách giảm data transfer cost

10. Decision Matrix

Hybridconnectivityneeded?│├──Yes,<1Gbps,cantolerateinternetvariability│└──Site-to-SiteVPN│├──Yes,>1GbpsORlatency-sensitiveORpredictableperf│├──Missioncritical→DX+DXbackup(MaximumResiliency)│├──Standardproduction→DX+VPNbackup│└──Cost-conscious→DXstandalone(acceptrisk)│├──Individualusersremoteaccess?│└──ClientVPN│└──EncryptionoverDXrequired(HIPAA,etc.)?└──VPNoverDX

Phần 3: Amazon Route 53

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.com└──mail.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-1→ALB-us-east└──Recordap-southeast-1→ALB-ap-southeastUserVN→Latencythấpnhấtđếnap-southeast-1→ALB-ap-southeastUserUS→Latencythấpnhấtđếnus-east-1→ALB-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=VN→ALBVietnam├──Country=JP→ALBJapan├──Continent=NA→ALBUS└──Default→ALBglobal
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: $0.50/check/tháng (free 50 checks đầu, cùng account)
  • Endpoint outside AWS: $0.75/check/tháng
  • Optional features (HTTPS, string matching, fast interval...): $1-2/feature/tháng
  • Calculated: $1/check/tháng
  • CW alarm-based: $1/check/tháng

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-east└──LatencyrecordB(eu-west-1)+HealthcheckonALB-eu-westIfALB-us-eastdown:→R53khôngreturnrecordA→TấtcảusersroutetoALB-eu-west(vẫnclosestlatencywise)

Example 2: Blue/Green deployment với weighted

example.com:├──Blue:95%weight(production)└──Green:5%weight(canarynewversion)Teststable→increaseGreenweightgradually→100%

Example 3: Geolocation cho compliance

api.example.com:├──EUcountries→ALB-eu-west(GDPR-compliant)├──US→ALB-us-east└──Default→ALB-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-premDNS←──InboundResolverEndpoint──VPC(query*.internal)│└─►Resolvesinternal.example.com(AWS)VPC───OutboundResolverEndpoint──►On-premDNS(forwardquery)Forwardingrules:corp.example.com→on-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. Gateway Endpoint hỗ trợ những services nào? Cost?

    Xem đáp án

    Gateway Endpoint chỉ hỗ trợ S3 và DynamoDB. Hoàn toàn miễn phí (không tốn tiền). Gateway Endpoint được add vào route table như một prefix list entry — traffic đến S3/DynamoDB route qua AWS network thay vì internet, không qua NAT Gateway (tiết kiệm NAT GW data processing fee $0.045/GB).

  2. Interface Endpoint có tạo ENI không? Tốn IP private không?

    Xem đáp án

    Có — Interface Endpoint tạo một ENI (Elastic Network Interface) trong subnet được chỉ định, với IP private từ subnet CIDR. Tốn 1 IP private per AZ per service. Interface Endpoint có phí: ~$0.01/giờ per AZ + $0.01/GB data processed. Hỗ trợ hầu hết AWS services (EC2, SSM, SNS, SQS, Kinesis, API Gateway...) và custom services qua PrivateLink.

  3. PrivateLink khác Interface Endpoint thế nào?

    Xem đáp án

    Interface Endpoint là consumer side (trong VPC của bạn) sử dụng PrivateLink để access AWS services hoặc 3rd-party services. AWS PrivateLink là technology/framework đằng sau — cho phép service providers (AWS hoặc bạn) expose services qua NLB, consumers access qua Interface Endpoint. PrivateLink = technology; Interface Endpoint = implementation consumer sử dụng.

  4. Để force S3 bucket chỉ accessible từ VPC Endpoint cụ thể, dùng condition gì?

    Xem đáp án

    Dùng condition aws:SourceVpce trong S3 Bucket Policy: "Condition": {"StringEquals": {"aws:SourceVpce": "vpce-xxxxxx"}}. Hoặc dùng aws:SourceVpc để allow toàn bộ VPC. Kết hợp với Deny rule: "Effect": "Deny", "Condition": {"StringNotEquals": {"aws:SourceVpce": "vpce-xxx"}} — chỉ allow access từ endpoint cụ thể, block tất cả access khác kể cả qua internet.

  5. Khi nào nên dùng VPC Endpoint thay vì NAT Gateway?

    Xem đáp án

    Khi traffic đến AWS services (S3, DynamoDB, SSM, SQS...) từ private subnet. Lý do: (1) Bảo mật — traffic không qua internet public, (2) Chi phí — Gateway Endpoint miễn phí, Interface Endpoint rẻ hơn NAT GW cho traffic volume lớn, (3) Latency — direct private network path. NAT Gateway vẫn cần cho internet access (non-AWS destinations). Pattern tốt nhất: VPC Endpoint cho AWS services + NAT GW cho internet thông thường.

  6. Site-to-Site VPN bandwidth per tunnel là bao nhiêu?

    Xem đáp án

    Mỗi tunnel Site-to-Site VPN tối đa 1.25 Gbps. Mỗi VPN connection có 2 tunnels (HA — nếu 1 tunnel fail, traffic chuyển sang tunnel kia). Để đạt throughput cao hơn, có thể dùng Accelerated Site-to-Site VPN (qua Global Accelerator) hoặc multiple VPN connections với ECMP trên Transit Gateway. Direct Connect cung cấp 1, 10, hoặc 100 Gbps.

  7. Direct Connect có encrypted by default không?

    Xem đáp án

    Không — Direct Connect là dedicated private network connection, nhưng không encrypted by default. Data in transit không encrypt. Để encrypt, dùng MACsec (Layer 2 encryption trên DX connection) hoặc overlay Site-to-Site VPN qua DX (IPSec encryption ở Layer 3). Với compliance requirements cần encryption in transit, phải implement thêm một trong hai layers.

  8. Direct Connect Gateway giải quyết vấn đề gì?

    Xem đáp án

    DX Gateway cho phép 1 Direct Connect connection access nhiều VPCs trong nhiều Regions (và nhiều AWS accounts). Không có DX Gateway: phải có riêng VIF cho mỗi VPC. Với DX Gateway: 1 Private VIF connect đến DX Gateway, gateway forward đến nhiều VGWs (Virtual Private Gateways) trong các VPCs khác nhau — hub-and-spoke model cho Direct Connect.

  9. VIF nào dùng để access S3 qua DX?

    Xem đáp án

    Public VIF (Public Virtual Interface). S3 là public AWS service với public IPs — cần Public VIF để access qua DX. Private VIF chỉ access resources trong VPC private IP space. Transit VIF dùng với Transit Gateway. Note: tuy gọi là "Public" VIF, traffic vẫn đi qua DX connection (not internet) — bảo mật hơn và không tính internet data transfer charge.

  10. Khác biệt giữa Client VPN và Site-to-Site VPN?

Xem đáp án

Site-to-Site VPN: kết nối network-to-network — on-premises network toàn bộ connect đến AWS VPC qua VGW và Customer Gateway. Dùng cho văn phòng hoặc datacenter cần kết nối thường xuyên đến AWS. Client VPN: kết nối individual device (laptop, remote worker) đến AWS VPC qua OpenVPN client. Mỗi user cần client software và certificate. Dùng cho remote workers cần access AWS resources.

  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.

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

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

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

  1. 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 Gateway Endpoint cho S3 trong VPC, observe route table thay đổi
  • Test EC2 trong private subnet (không NAT GW) access S3 qua endpoint
  • Tạo Interface Endpoint cho SQS với Private DNS enabled
  • Apply endpoint policy restrict S3 endpoint chỉ cho 1 bucket
  • Setup PrivateLink: tạo NLB + Endpoint Service trong 1 VPC, consume từ VPC khác

Phần 2: VPN và Direct Connect Intro

  • Setup Site-to-Site VPN với CGW giả lập (pfSense trên EC2 ở VPC khác hoặc test environment)
  • Tạo Client VPN endpoint với mutual TLS, test connect từ laptop
  • Vẽ architecture diagram cho hybrid: on-prem DC connect 3 AWS VPCs khác Region
  • So sánh cost: VPN vs DX 1 Gbps cho 1 TB data/month

Phần 3: Amazon Route 53

  • 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


Bài tiếp theo →