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

Tuần 4 - Ngày 1: VPC Advanced Concepts

Tuần 4 – Ngày 1

Tuần 4 - Ngày 1: VPC Advanced Concepts

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

  • Hiểu sâu về VPC Endpoints
  • Nắm vững VPC Peering và limitations
  • Biết cách thiết kế multi-VPC architectures

1. VPC Endpoints

Types of VPC Endpoints

VPCENDPOINTSGatewayEndpoints(Free)SupportedServices:-S3-DynamoDBHowitworks:-Entryinroutetable-TrafficstayswithinAWSnetwork-ChaccesstresourceTRONGVPC-KHÔNGaccessđưcton-premises(DirectConnect/VPN)InterfaceEndpoints(Paid)SupportedServices:-MostAWSservices(100+)-AWSPrivateLinkservices-DynamoDB(quaPrivateLink,GA2023)-S3(PrivateLink,dùngchoon-premaccess)Howitworks:-ENIinyoursubnet-PrivateIPaddress-DNSresolutiontoprivateIP-Accessđưcton-premisesquaDX/VPNGatewayLoadBalancerEndpointsFor:Third-partyvirtualappliances-Firewalls-IDS/IPS-Deeppacketinspection

Gateway Endpoint Architecture

VPCPrivateSubnetEC2RouteTable:DestinationTarget10.0.0.0/16localpl-xxxxx(S3)vpce-xxxxx(GWEP)GatewayEndpoint(vpce-xxxxx)S3

Interface Endpoint Architecture

VPCPrivateSubnetEC2InterfaceEndpoint(ENI:10.0.1.100)DNS:secrets.manager.ap-southeast-1.amazonaws.comAWSPrivateLinkSecretsManager

Endpoint Policies

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

DynamoDB: Gateway vs Interface Endpoint

DynamoDB hỗ trợ cả hai loại endpoint — biết lựa chọn nào cho SAP-C02 scenario là quan trọng.

Tiêu chíDynamoDB Gateway EndpointDynamoDB Interface Endpoint (PrivateLink)
PricingMiễn phí$0.01/giờ/AZ + data processing
Access từ trong VPC
Access từ on-premises (DX/VPN)✗ Không hỗ trợ✓ Có
Cross-region access✓ (qua VPC peering / TGW)
SetupAdd route vào route tableTạo ENI trong subnet
DNS resolutionPublic DNS → private routePrivate DNS name
Use case mặc địnhMọi traffic trong VPCHybrid: on-prem cần truy cập DynamoDB

Exam keyword:

  • "Most cost-effective access to DynamoDB from VPC" → Gateway Endpoint (free)
  • "Access DynamoDB from on-premises through Direct Connect/VPN" → Interface Endpoint (PrivateLink)
  • "Hybrid architecture, on-prem app calls DynamoDB privately" → Interface Endpoint

Lưu ý: S3 cũng có cả hai loại endpoint với pattern tương tự (S3 Interface Endpoint GA 2021 cho hybrid use case).

2. VPC Peering

How it works

VPCAPeeringVPCB10.0.0.0/16172.16.0.0/16RouteTable:RouteTable:172.16.0.0/1610.0.0.0/16pcx-xxxxxpcx-xxxxx

Key Characteristics

  • Non-transitive: Traffic cannot transit through peered VPC
  • Cross-region: Supported with inter-region peering
  • Cross-account: Supported with accepter approval
  • No overlapping CIDR: VPCs cannot have overlapping IP ranges

Transitive Peering Problem

VPCAPeeringVPCBPeeringVPCCAB:(directpeering)BC:(directpeering)AC:(notransitiverouting)Solution:UseTransitGateway

VPC Peering Limitations

LimitationDetail
Max peers per VPC125
BandwidthNo aggregate limit
Transitive routingNot supported
Overlapping CIDRNot supported
DNS resolutionNeeds enablement

3. Multi-VPC Architectures

Pattern 1: Hub-and-Spoke (Full Mesh Peering)

VPCHub(Shared)VPCSpoke1VPCSpoke2VPCSpoke3(ProdApp1)(ProdApp2)(Dev)Pros:Simple,noadditionalcostCons:Doesnotscalewell(n*(n-1)/2peerings)
TransitGatewayVPC1VPC2VPC3VPNDXPros:Scaleswell,centralizedmanagementCons:Per-attachmentandper-GBcost

4. Private DNS with VPC

Route 53 Private Hosted Zone

Route53PrivateHostedZone(internal.company.com)Records:-app.internal.company.com10.0.1.50-db.internal.company.com10.0.2.100-api.internal.company.com10.0.3.75AssociatedwithVPCs:VPCAVPCBVPCC(Prod)(Dev)(Test)

Route 53 Resolver

On-PremisesAWS:On-PremisesDNSQueryVPCDNSServerInbound(ForwardtoAWS)EndpointAWSOn-Premises:VPCDNSQueryOn-PremisesOutboundDNSServerEndpoint(Forwardtoon-prem)

5. VPC Design Best Practices

CIDR Planning

CompanyCIDR:10.0.0.0/8Production:10.0.0.0/12(1MIPs)Prod-VPC-1:10.0.0.0/16Prod-VPC-2:10.1.0.0/16Prod-VPC-3:10.2.0.0/16Development:10.64.0.0/12(1MIPs)Dev-VPC-1:10.64.0.0/16Dev-VPC-2:10.65.0.0/16Testing:10.128.0.0/12(1MIPs)Test-VPC-1:10.128.0.0/16

Subnet Design

VPCCIDR:10.0.0.0/16AZ-aSubnets:Public:10.0.0.0/24(Webservers,ALB)Private:10.0.1.0/24(Appservers)Database:10.0.2.0/24(RDS,ElastiCache)Reserved:10.0.3.0/24(Futureuse)AZ-bSubnets:Public:10.0.10.0/24Private:10.0.11.0/24Database:10.0.12.0/24Reserved:10.0.13.0/24AZ-cSubnets:Public:10.0.20.0/24Private:10.0.21.0/24Database:10.0.22.0/24Reserved:10.0.23.0/24

6. Câu hỏi ôn tập

  1. Gateway Endpoint và Interface Endpoint khác nhau như thế nào?

    Xem đáp án

    Gateway Endpoint: chỉ S3 và DynamoDB, miễn phí, được add vào route table, không tạo ENI. Interface Endpoint: hầu hết AWS services, có phí (~$0.01/giờ/AZ + $0.01/GB), tạo ENI với Private IP trong subnet, hỗ trợ Private DNS. Interface Endpoint dùng PrivateLink — có thể dùng cho custom services (qua NLB). Gateway Endpoint đơn giản và miễn phí cho S3/DynamoDB; Interface Endpoint cho other services cần private access.

  2. VPC Peering có hỗ trợ transitive routing không?

    Xem đáp án

    Không — VPC Peering không có transitive routing. Nếu A-B peer và B-C peer: A không thể reach C qua B. Phải tạo direct A-C peering. Với nhiều VPCs (N VPCs), cần N×(N-1)/2 peering connections — không scalable. Transit Gateway giải quyết: hub-and-spoke, transitive routing, N connections thay vì N² connections.

  3. Khi nào nên dùng VPC Peering vs Transit Gateway?

    Xem đáp án

    VPC Peering khi: 2-4 VPCs cần kết nối, không cần transitive routing, muốn giảm cost (peering miễn phí, TGW có phí attachment + processing), không cần centralized routing control. Transit Gateway khi: nhiều hơn 5 VPCs, cần transitive routing, cần centralized network hub (VPN + DX + VPCs từ 1 điểm), cần cross-region (TGW peering), cần network segmentation với route tables riêng.

  4. Route 53 Resolver Inbound endpoint dùng để làm gì?

    Xem đáp án

    Inbound Endpoint cho phép on-premises DNS servers forward queries đến Route 53 Resolver để resolve AWS private hosted zones và VPC internal hostnames. On-premises DNS forward requests đến Inbound Endpoint IPs (trong VPC) qua Direct Connect hoặc VPN. Ngược lại, Outbound Endpoint cho phép VPC EC2 instances forward DNS queries ra on-premises DNS servers.

  5. Tại sao cần plan CIDR ranges carefully?

    Xem đáp án

    Overlapping CIDRs gây không thể peering VPCs (VPC Peering không hoạt động với overlapping CIDRs). Với Transit Gateway, overlapping CIDRs gây routing ambiguity. Multi-account environments cần non-overlapping CIDRs across tất cả VPCs/accounts. AWS IPAM giúp centralize CIDR management. Planning từ đầu: assign CIDR ranges per account/Region (ví dụ: 10.0.0.0/8 cho toàn org, chia /12 per region, /16 per account).

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

  • Create S3 Gateway Endpoint
  • Create Interface Endpoint for Secrets Manager
  • Setup VPC Peering between 2 VPCs
  • Configure Route 53 Private Hosted Zone

Tài liệu tham khảo chính thức


Ngày tiếp theo: Transit Gateway Deep Dive