devHọc Dev
EN
Bài học

Tuần 2 - Ngày 4: VPN, Hybrid Connectivity và Route 53 nâng cao

Tuần 2 – Ngày 4

Bài này gộp 2 chủ đề: VPN và Hybrid Connectivity, Route 53 Advanced.

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

  • Hiểu các VPN options trên AWS
  • Nắm vững Site-to-Site VPN configuration
  • Biết cách thiết kế hybrid architectures
  • Hiểu các routing policies nâng cao
  • Nắm vững health checks và failover
  • Biết cách implement DNS-based architectures

Phần 1: VPN và Hybrid Connectivity

1. AWS VPN Options

Types of VPN

┌─────────────────────────────────────────────────────────┐│AWSVPNOPTIONS││││1.AWSSite-to-SiteVPN││├──Connecton-premisesnetworktoVPC││├──EncryptedIPsectunnelsoverinternet││└──ManagedbyAWS││││2.AWSClientVPN││├──Remoteaccessforindividualusers││├──OpenVPN-basedclient││└──Managedelasticendpoint││││3.AWSVPNCloudHub││├──Connectmultipleon-premisessites││├──Hub-and-spokeviaAWS││└──UsesVirtualPrivateGateway│└─────────────────────────────────────────────────────────┘

2. Site-to-Site VPN Components

Architecture

┌─────────────────────────────────────────────────────────┐│On-PremisesNetwork││││┌─────────────────────────────────────────────────┐│││CustomerGateway(CGW)││││(YourVPNdevice)││││IP:203.0.113.1│││└───────────────────────┬─────────────────────────┘│└──────────────────────────┼──────────────────────────────┘│IPsecTunnels(2tunnelsforHA)│┌──────────────────────────┼──────────────────────────────┐│AWS│││││┌───────────────────────┴─────────────────────────┐│││VirtualPrivateGateway(VGW)││││ORTransitGateway││││││││Tunnel1:169.254.x.x/30││││Tunnel2:169.254.y.y/30│││└───────────────────────┬─────────────────────────┘│││││▼││┌──────────────┐│││VPC││││10.0.0.0/16│││└──────────────┘│└─────────────────────────────────────────────────────────┘

Customer Gateway (CGW)

Requirements for CGW device:
- IKEv1 or IKEv2 support
- IPsec support
- BGP (optional but recommended)
- Static public IP address

Supported devices:
- Cisco (ASA, IOS, IOS-XE)
- Juniper
- Palo Alto
- Fortinet
- pfSense
- Many others...

3. VPN Tunnel Configuration

Two Tunnels for HA

┌─────────────────────────────────────────────────────────┐│VPNConnection││││┌─────────────────────────────────────────────────┐│││Tunnel1(Primary-AZ-a)││││OutsideIP:35.x.x.x(AWSendpoint)││││InsideIP:169.254.10.0/30││││Pre-sharedKey:*****││││Status:UP│││└─────────────────────────────────────────────────┘││││┌─────────────────────────────────────────────────┐│││Tunnel2(Secondary-AZ-b)││││OutsideIP:52.x.x.x(AWSendpoint)││││InsideIP:169.254.20.0/30││││Pre-sharedKey:*****││││Status:UP│││└─────────────────────────────────────────────────┘││││BestPractice:ConfigurebothtunnelsonCGW│└─────────────────────────────────────────────────────────┘

Routing Options

1. Static Routing:
   - Manually specify on-premises CIDR
   - Simple but no automatic failover

2. Dynamic Routing (BGP):
   - Exchange routes automatically
   - Faster failover
   - Recommended for production

BGP Configuration:
- AWS ASN: 64512 (default) or custom
- Customer ASN: Your ASN
- BGP over tunnel inside IPs

4. Accelerated Site-to-Site VPN

With AWS Global Accelerator

WithoutAcceleration:┌────────────┐InternetPath┌─────────────┐│On-Premises│──────────────────►│AWSVPN│││Variablelatency│Endpoint│└────────────┘└─────────────┘WithAcceleration:┌────────────┐┌──────────────┐┌─────────────┐│On-Premises│──►│NearestEdge│──►│AWSVPN││││Location││Endpoint│└────────────┘└──────────────┘└─────────────┘AWSBackbone(Moreconsistent)Benefits:-Lowerlatency-Lessjitter-Moreconsistentperformance-UsesAWSglobalnetworkRequirement:-CHỈhỗtrợVPNattachvàoTransitGateway-VirtualPrivateGateway(VGW)KHÔNGhỗtrợacceleration-Bậtaccelerationlúctạoconnection(khôngbậtthêmsau)

Bẫy đề thi: kiến trúc đang dùng VGW muốn "giảm latency/jitter cho VPN" → phải chuyển VPN sang Transit Gateway attachment rồi mới bật Accelerated VPN. Đáp án chỉ "bật acceleration trên VGW" là sai.

5. AWS Client VPN

Architecture

┌─────────────────────────────────────────────────────────┐│AWSClientVPN││││┌─────────────────────────────────────────────────┐│││ClientVPNEndpoint││││(ManagedbyAWS)││││││││Authentication:││││-ActiveDirectory││││-SAML(Okta,AzureAD)││││-Mutualauthentication(certificates)│││└───────────────────────┬─────────────────────────┘│││││┌─────────────┴─────────────┐││▼▼││┌──────────────┐┌──────────────┐│││VPC││On-Premises││││Resources││(viaVGW)│││└──────────────┘└──────────────┘│└─────────────────────────────────────────────────────────┘▲│OpenVPNclient│┌─────────────┐│RemoteUser││(Laptop)│└─────────────┘

Use Cases

  • Remote worker access
  • Contractor access
  • Emergency access during disaster

6. VPN CloudHub

Hub-and-Spoke Connectivity

┌─────────────────┐│VirtualPrivate││Gateway││(VGW)│└────────┬────────┘│┌──────────────────────┼──────────────────────┐│││▼▼▼┌─────────┐┌─────────┐┌─────────┐│CGW1││CGW2││CGW3││SiteA││SiteB││SiteC│└─────────┘└─────────┘└─────────┘192.168.1.0/24192.168.2.0/24192.168.3.0/24Trafficflow:-SiteA↔AWSVPC:Direct-SiteA↔SiteB:ViaVGW(hub)-AllsitesusesameVGWashub

7. Hybrid Architecture Patterns

Pattern 1: VPN Only

Best for:
- Getting started with hybrid
- Lower bandwidth requirements (<1.25 Gbps)
- Quick setup needed
- Backup for Direct Connect

Limitations:
- Performance varies with internet
- Max ~1.25 Gbps per tunnel

Pattern 2: Direct Connect + VPN Backup

┌─────────────────┐│On-Premises││││┌───────────┐│┌─────────────────────────────┐││Router│──┼────►│DirectConnect(Primary)││││││││││──┼────►│Site-to-SiteVPN(Backup)││└───────────┘│└─────────────────────────────┘└─────────────────┘Failover:1.DXfails2.BGPdetectsfailure(BFDifenabled)3.TrafficshiftstoVPN4.WhenDXrecovers,trafficreturns

Pattern 3: Dual Direct Connect

┌─────────────────┐│On-Premises││││┌───────────┐│┌─────────────────────────────┐││Router1│──┼────►│DXLocation1││└───────────┘│└─────────────────────────────┘│││┌───────────┐│┌─────────────────────────────┐││Router2│──┼────►│DXLocation2││└───────────┘│└─────────────────────────────┘└─────────────────┘Highestavailabilitybutmostexpensive

8. VPN Performance Tuning

Bandwidth Optimization

SingleVPN:1.25GbpspertunnelWithECMP(TransitGateway):┌─────────────────────────────────────────────────────────┐│MultipleVPNconnections+ECMP││││VPN1:1.25Gbps─┐││VPN2:1.25Gbps─┼─►TransitGateway││VPN3:1.25Gbps─┘(ECMPenabled)││││Total:3.75Gbps││Canscaleupto50Gbps│└─────────────────────────────────────────────────────────┘

Latency Optimization

1. Use Accelerated Site-to-Site VPN
2. Enable Dead Peer Detection (DPD)
3. Configure BFD for fast failover
4. Use BGP for dynamic routing

Phần 2: Route 53 Advanced

1. Route 53 Routing Policies

Overview

┌─────────────────────────────────────────────────────────┐│ROUTE53ROUTINGPOLICIES││││1.Simple-Singleresource,nohealthcheck││2.Weighted-Distributetrafficbyweight││3.Latency-Routetolowestlatencyregion││4.Failover-Active-passivefailover││5.Geolocation-Routebyuserlocation││6.Geoproximity-Routebygeographicdistance││7.IP-based-RoutebyclientIP││8.Multivalue-Returnmultiplehealthyvalues│└─────────────────────────────────────────────────────────┘

Weighted Routing

┌─────────────────────────────────────────────────────────┐│WeightedRouting││││app.example.com│││││├──RecordA:Weight70→10.0.1.1(Primary)│││││├──RecordB:Weight20→10.0.2.1(Secondary)│││││└──RecordC:Weight10→10.0.3.1(Canary)││││TrafficDistribution:││-70%→Primary││-20%→Secondary││-10%→Canary│└─────────────────────────────────────────────────────────┘Usecases:-Blue/Greendeployments-A/Btesting-Gradualmigration

Latency Routing

┌─────────────────────────────────────────────────────────┐│LatencyRouting││││UserinSingapore│││││▼││┌─────────────┐│││Route53││││Latency││││Check│││└──────┬──────┘│││││┌──────┴─────────────────────────────────────┐││││││▼Lowestlatency▼││ap-southeast-1us-east-1eu-west-1││(50ms)✓(200ms)(250ms)│└─────────────────────────────────────────────────────────┘Note:LatencyismeasuredAWSregiontouser,notabsolute

Geolocation Routing

┌─────────────────────────────────────────────────────────┐│GeolocationRouting││││┌─────────────────────────────────────────────────┐│││Record1:Location=Asia││││→ap-southeast-1servers│││├─────────────────────────────────────────────────┤│││Record2:Location=Europe││││→eu-west-1servers│││├─────────────────────────────────────────────────┤│││Record3:Location=Default││││→us-east-1servers(fallback)│││└─────────────────────────────────────────────────┘││││Usecases:││-Contentlocalization││-Regulatorycompliance(dataresidency)││-Loadbalancingbyregion│└─────────────────────────────────────────────────────────┘

Geoproximity Routing

┌─────────────────────────────────────────────────────────┐│GeoproximityRouting││(recordthườngtronghostedzone,bias-99..+99)││││ResourceswithBias:││┌─────────────────────────────────────────────────┐│││Region:us-east-1││││Bias:+25││││→Attractsmoretrafficfromnearbyareas│││├─────────────────────────────────────────────────┤│││Region:us-west-2││││Bias:-10││││→Pushestrafficaway│││└─────────────────────────────────────────────────┘││││Biasrange:-99to+99││Usecase:Shifttrafficduringmaintenance│└─────────────────────────────────────────────────────────┘

Cập nhật 01/2024: Geoproximity trước đây chỉ tạo được qua Traffic Flow (traffic policy, tính phí). Từ tháng 1/2024, geoproximity là routing policy chuẩn — tạo trực tiếp như record thường trong public hoặc private hosted zone, qua console/API/CLI/CloudFormation. Traffic Flow chỉ còn cần khi muốn dùng visual editor hoặc kết hợp nhiều rule trong một traffic policy. Câu hỏi "geoproximity yêu cầu Traffic Flow" là kiến thức lỗi thời.

IP-based Routing

┌─────────────────────────────────────────────────────────┐│IP-basedRouting││││CIDRCollections:││┌─────────────────────────────────────────────────┐│││Collection:"CorporateIPs"││││CIDRs:203.0.113.0/24,198.51.100.0/24││││→Routetointernalendpoints│││├─────────────────────────────────────────────────┤│││Collection:"PartnerIPs"││││CIDRs:192.0.2.0/24││││→Routetopartnerendpoints│││├─────────────────────────────────────────────────┤│││Default││││→Routetopublicendpoints│││└─────────────────────────────────────────────────┘││││Usecases:││-ISP-specificrouting││-Corporatenetworkoptimization│└─────────────────────────────────────────────────────────┘

2. Health Checks

Types of Health Checks

1. Endpoint Health Checks:
   - HTTP/HTTPS/TCP
   - Check specific endpoint
   - Configure threshold

2. Calculated Health Checks:
   - Combine multiple health checks
   - AND, OR logic

3. CloudWatch Alarm Health Checks:
   - Based on CloudWatch alarm state
   - For private resources

Health Check Configuration

┌─────────────────────────────────────────────────────────┐│HealthCheckSettings││││Protocol:HTTPS││Endpoint:api.example.com││Port:443││Path:/health││││RequestInterval:30seconds(or10forfast)││FailureThreshold:3││││StringMatching:"healthy"(optional)││LatencyGraphs:Enabled││││Regions:All(recommended)││Orspecificregions│└─────────────────────────────────────────────────────────┘

Calculated Health Checks

┌─────────────────────────────────────────────────────────┐│CalculatedHealthCheck││││┌─────────────────────────────────────────────────┐│││ParentHealthCheck││││││││Logic:Reporthealthywhenatleast2of3││││childhealthchecksarehealthy││││││││┌──────────┐┌──────────┐┌──────────┐│││││Child1││Child2││Child3││││││(Web)││(API)││(DB)││││││Healthy││Healthy││Unhealthy│││││└──────────┘└──────────┘└──────────┘││││││││Result:Parent=HEALTHY(2of3)│││└─────────────────────────────────────────────────┘│└─────────────────────────────────────────────────────────┘

3. Failover Routing

Active-Passive Failover

┌─────────────────────────────────────────────────────────┐│Active-PassiveFailover││││app.example.com│││││├─►Primary(Active)│││-Failovertype:Primary│││-Healthcheck:hc-primary│││-Target:10.0.1.1(mainserver)│││││└─►Secondary(Passive)││-Failovertype:Secondary││-Healthcheck:optional││-Target:10.0.2.1(backupserver)││││Flow:││1.Primaryhealthy→TraffictoPrimary││2.Primaryfails→TraffictoSecondary││3.Primaryrecovers→TrafficbacktoPrimary│└─────────────────────────────────────────────────────────┘

Active-Active with Health Checks

┌─────────────────────────────────────────────────────────┐│Active-ActivewithWeighted+Health││││┌─────────────────────────────────────────────────┐│││Record1:Weight50,HealthCheckenabled││││→us-east-1(Healthy✓)│││├─────────────────────────────────────────────────┤│││Record2:Weight50,HealthCheckenabled││││→us-west-2(Unhealthy✗)│││└─────────────────────────────────────────────────┘││││Result:100%traffictous-east-1││(Unhealthyrecordsremovedfromresponses)│└─────────────────────────────────────────────────────────┘

4. Route 53 Resolver

DNS Resolution for Hybrid

┌─────────────────────────────────────────────────────────┐│Route53Resolver││││AWS→On-Premises(Outbound):││┌─────────────────────────────────────────────────┐│││VPC││││┌──────────────┐│││││Outbound│──►corp.internal.com│││││Endpoint│(Forwardtoon-premDNS)││││└──────────────┘│││└─────────────────────────────────────────────────┘││││On-Premises→AWS(Inbound):││┌─────────────────────────────────────────────────┐│││VPC││││┌──────────────┐│││││Inbound│◄──aws.example.com│││││Endpoint│(On-premforwardshere)││││└──────────────┘│││└─────────────────────────────────────────────────┘│└─────────────────────────────────────────────────────────┘

Resolver Rules

┌─────────────────────────────────────────────────────────┐│ResolverRules││││Rule1:Forward││┌─────────────────────────────────────────────────┐│││Domain:corp.internal││││Type:Forward││││Target:192.168.1.10,192.168.1.11││││(On-premisesDNSservers)│││└─────────────────────────────────────────────────┘││││Rule2:System││┌─────────────────────────────────────────────────┐│││Domain:amazonaws.com││││Type:System││││Action:UseRoute53Resolver│││└─────────────────────────────────────────────────┘││││CansharerulesviaRAMacrossaccounts│└─────────────────────────────────────────────────────────┘

5. Private Hosted Zones

Cross-Account PHZ Sharing

┌─────────────────────────────────────────────────────────┐│PrivateHostedZoneSharing││││┌─────────────────────────────────────────────────┐│││AccountA(DNSOwner)││││││││PrivateHostedZone:internal.company.com││││AssociatedVPCs:VPC-A││││││││+AuthorizeAccountB'sVPC│││└─────────────────────────────────────────────────┘│││││Authorization│││││┌─────────────────────────────────────────────────┐│││AccountB││││││││VPC-B:AssociateswithPHZ││││Canresolveinternal.company.com│││└─────────────────────────────────────────────────┘│└─────────────────────────────────────────────────────────┘Steps:1.AccountAcreatesPHZandassociatesVPC-A2.AccountAauthorizesAccountB'sVPC3.AccountBassociatesVPC-BwithPHZ4.AccountAdeletesauthorization(optional)

6. DNS Best Practices

TTL Strategy

RecordTypeRecommendedTTL───────────────────────────────────Staticrecords86400(1day)Loadbalanced60-300secondsFailover60secondsorlessDuringmigration300→60→original

Alias vs CNAME

┌─────────────────────────────────────────────────────────┐│ALIASvsCNAME││││ALIAS(AWS-specific):││✓Canbeusedatzoneapex(example.com)││✓Nochargeforqueries││✓Nativehealthcheckintegration││✓ReturnsA/AAAArecords││││CNAME:││✗Cannotbeusedatzoneapex││✗Chargedforqueries││✗AdditionalDNSlookuprequired││✓Workswithnon-AWSresources││││Recommendation:UseALIASforAWSresources│└─────────────────────────────────────────────────────────┘

Câu hỏi ôn tập

  1. Site-to-Site VPN có bao nhiêu tunnels?

    Xem đáp án

    2 tunnels per VPN connection — active-active (BGP) hoặc active-standby. Hai tunnels terminate ở 2 endpoints AWS khác nhau (different AZ) để HA. Mỗi tunnel max 1.25 Gbps. Cả hai tunnels nên được config trên Customer Gateway device. Nếu chỉ dùng 1 tunnel: không có redundancy phía AWS side. BGP ưu tiên tunnel với best path; non-BGP (static routing) thường dùng active-standby.

  2. Accelerated VPN khác VPN thường như thế nào?

    Xem đáp án

    Accelerated VPN (Accelerated Site-to-Site VPN) route traffic qua AWS Global Accelerator anycast IPs — traffic vào AWS network tại Edge Location gần nhất, rồi traverse AWS backbone. Giảm latency và jitter so với routing toàn bộ qua public internet. Phù hợp cho: global on-premises offices cách xa AWS Region, latency-sensitive applications, gaming/VoIP qua VPN. Điều kiện: VPN connection phải attach vào Transit Gateway — Virtual Private Gateway không hỗ trợ accelerated VPN. Chi phí thêm Global Accelerator fee (~$0.025/giờ + data fees).

  3. Client VPN dùng authentication methods nào?

    Xem đáp án

    3 methods: (1) Active Directory (AWS Managed Microsoft AD hoặc AD Connector — authenticate bằng corporate credentials), (2) Certificate-based (mutual TLS — client và server đều có certificates từ CA), (3) SAML-based federated authentication (Okta, Azure AD, Ping Identity). Có thể kết hợp AD + Certificate. Client VPN dùng OpenVPN protocol — compatible với nhiều VPN clients (AWS VPN Client, OpenVPN Connect).

  4. VPN CloudHub dùng để làm gì?

    Xem đáp án

    VPN CloudHub cho phép nhiều on-premises sites giao tiếp với nhau qua AWS như một hub. Mỗi site có Site-to-Site VPN kết nối đến cùng VGW (Virtual Private Gateway). Traffic từ Site A → AWS VGW → Site B — AWS đóng vai trò trung gian. Phù hợp cho công ty có nhiều văn phòng cần kết nối với nhau mà không cần MPLS network riêng. Không phải service riêng — chỉ là architecture pattern với existing VPN.

  5. Làm sao để tăng VPN bandwidth?

    Xem đáp án

    (1) Multiple VPN connections + ECMP qua Transit Gateway — nhiều connections parallel, aggregate bandwidth. (2) Accelerated VPN giảm latency nhưng không tăng throughput per tunnel. (3) Nếu cần > 10 Gbps: migrate sang Direct Connect (1G, 10G, hoặc 100G). Với TGW + ECMP: N VPN connections × 2 tunnels/connection × 1.25 Gbps/tunnel = N × 2.5 Gbps. Cần Customer Gateway device hỗ trợ ECMP và BGP.

  6. 8 routing policies của Route 53 là gì?

    Xem đáp án

    (1) Simple — single resource, no health check, (2) Weighted — % traffic theo weight, A/B testing, (3) Latency-based — route đến Region có lowest latency, (4) Failover — active-passive với health check, (5) Geolocation — route theo country/continent của user, (6) Geoproximity — route theo geographic proximity với bias -99..+99 (từ 01/2024 tạo trực tiếp trong hosted zone, không cần Traffic Flow), (7) Multivalue Answer — multiple healthy IPs, (8) IP-based — route theo client IP CIDR prefix (ra mắt 06/2022).

  7. Geolocation khác Latency routing như thế nào?

    Xem đáp án

    Geolocation: route dựa trên địa lý vật lý (country, continent, subdivision) — user từ Vietnam luôn đến endpoint được assign cho Vietnam/Asia, bất kể latency. Dùng cho compliance (data residency), localization (show Vietnamese content), content restrictions. Latency-based: route đến Region có latency thấp nhất — user từ Vietnam có thể đến Singapore hay Tokyo tùy latency tốt hơn. Dùng cho performance optimization.

  8. Health check types là gì?

    Xem đáp án

    3 types: (1) Endpoint health checks — monitor HTTP/HTTPS/TCP endpoint trực tiếp (Route 53 health checkers từ nhiều Regions), (2) Calculated health checks — combine status của multiple health checks (AND/OR logic), (3) CloudWatch alarm health checks — trạng thái dựa trên CloudWatch alarm state. Health check frequency: 30s (standard) hoặc 10s (fast, thêm chi phí). Cơ chế đánh giá: endpoint được coi là healthy khi > 18% health checkers (phân bố nhiều Regions) báo healthy; còn Failure Threshold (mặc định 3) là số lần check fail liên tiếp mà mỗi checker cần thấy trước khi báo unhealthy — hai khái niệm khác nhau, đừng nhầm.

  9. Route 53 Resolver dùng để làm gì?

    Xem đáp án

    Route 53 Resolver là DNS resolver trong VPC (mặc định tại 169.254.169.253). Resolver Endpoints cho hybrid connectivity: Inbound Endpoint — on-premises DNS forward queries đến AWS để resolve Route 53 private zones; Outbound Endpoint — EC2 trong VPC forward queries đến on-premises DNS servers. Resolver Rules define which domains forward to which DNS servers. Cần cho Split-horizon DNS (same domain, different IPs internal vs external).

  10. ALIAS record khác CNAME như thế nào?

Xem đáp án

CNAME: DNS standard, map hostname → hostname khác, không dùng được tại apex domain (example.com bare domain), tính phí query. ALIAS: Route 53 extension, map hostname → AWS resources (ALB DNS name, CloudFront, S3 website, API GW, Elastic Beanstalk), dùng được tại apex domain, không tính phí query riêng, support health check, AWS auto-update IP nếu resource IP thay đổi. Luôn ưu tiên ALIAS cho AWS resources.

Bài tập thực hành

Phần 1: VPN và Hybrid Connectivity

  • Create Site-to-Site VPN connection
  • Download và review VPN configuration
  • Setup Client VPN endpoint
  • Test failover scenarios

Phần 2: Route 53 Advanced

  • Create weighted routing records
  • Setup health checks với failover
  • Configure Route 53 Resolver rules
  • Test failover scenarios

Tài liệu tham khảo


Bài tiếp theo →