devHọc Dev

Week 2 - Day 2: VPC Endpoints, VPN/Direct Connect and Route 53

Week 2 – Day 2

This lesson combines 3 topics: VPC Endpoints and PrivateLink, VPN and Direct Connect Intro, Amazon Route 53.

Learning Objectives

  • Distinguish Gateway Endpoint and Interface Endpoint
  • Understand PrivateLink for 3rd-party services
  • Know endpoint policies
  • Know when to use a VPC Endpoint vs a NAT Gateway
  • Understand Site-to-Site VPN architecture
  • Distinguish VPN, Direct Connect, Client VPN
  • Know the bandwidth and latency trade-offs
  • Know which one to use for hybrid connectivity
  • Understand what Route 53 is: DNS, registrar, health check
  • Distinguish record types (A, AAAA, CNAME, ALIAS)
  • Know the 7 routing policies
  • Know health checks and failover

1. VPC Endpoint Overview

The problem

When EC2 in a private subnet wants to access AWS services (S3, DynamoDB, SQS, KMS...):

  • Old way: route 0.0.0.0/0 → NAT GW → IGW → AWS service public endpoint
  • Problem: traffic goes over the internet → cost (NAT GW data processing), security concern

Solution: VPC Endpoint

  • Private connection from the VPC to AWS services
  • Traffic does NOT go over the internet
  • Reduces NAT GW cost, improves security

3 endpoint types

TypeServicesCostSetup
Gateway EndpointS3, DynamoDBFreeRoute table entry
Interface Endpoint (PrivateLink)Most AWS services$0.01/hour + $0.01/GBENI in subnet
Gateway Load Balancer EndpointFor appliances$/hourSpecifically for firewalls

2. Gateway Endpoint

Characteristics

  • Only for S3 and DynamoDB
  • Free (no extra charge)
  • Implemented as a route table entry (target = vpce-xxx)
  • Does not create an ENI, does not consume IPs
  • Only accessible from the VPC where the endpoint lives (not cross-VPC)

Setup

  1. Create a Gateway Endpoint for S3
  2. Select the relevant route table(s)
  3. AWS automatically adds the 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(viaAWSnetwork)

Endpoint Policy

  • Default: allow all access to the 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 in a private subnet uploading/downloading S3 (reduces NAT GW cost)
  • Lambda in a VPC accessing DynamoDB
  • Compliance: traffic does not leave the VPC

Characteristics

  • Supported by most AWS services (100+): SQS, SNS, KMS, Secrets Manager, ECR, ECS, EventBridge, API Gateway, ...
  • Implemented as an ENI in a subnet with a private IP
  • Accessed via DNS (private DNS can be enabled)
  • Cost: $0.01/hour per endpoint per AZ + $0.01/GB data processed
  • Supports cross-VPC via PrivateLink

Setup

  1. Create an Interface Endpoint for the service (e.g., com.amazonaws.us-east-1.sqs)
  2. Select subnet(s) — an ENI is created in each subnet
  3. Select a Security Group
  4. Enable Private DNS (recommended) → the public service URL automatically resolves to the 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 the private IP of the Interface Endpoint
→ No code changes needed

Endpoint Policy

  • Restrict actions, resources, principals
  • Applied per endpoint

Use case

  • Private subnet accessing SQS, Secrets Manager, KMS
  • Compliance (data does not go out to the internet)
  • Reduce NAT GW data processing cost

4. Endpoint Pricing Math Example

Scenario

EC2 in a private subnet pulls images from ECR, 100 GB per month.

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 for ECR
  • Endpoint: $0.01/hour × 730 × 1 AZ = $7.30/month
  • Data: $0.01/GB × 100 GB = $1.00/month
  • Total: ~$8.30/month (the ECR Docker Registry endpoint is also needed)

→ Saves ~$29/month with an endpoint for 100 GB.

Rules of thumb

  • An endpoint is cheaper than a NAT GW when data volume is large (> ~10 GB/month per service)
  • Multi-AZ Interface Endpoint = $0.01/hour × number of AZs

Definition

PrivateLink = expose a service in your VPC so that consumers in other VPCs (same/different account) can access it over a private network.

2 roles

  • Service provider: creates a VPC Endpoint Service from an NLB (or GWLB)
  • Service consumer: creates an Interface Endpoint that connects to the service

Architecture

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

Use cases

  • SaaS provider exposing an API via PrivateLink
  • Cross-account internal service sharing
  • Partner integration without the internet

Allowlist

  • The service provider whitelists consumer accounts/principals
  • Consumers must be approved before they can connect

6. Endpoint Services supporting Gateway/Interface

Gateway (free) — only 2 services

  • S3
  • DynamoDB

Interface ($) — most others

  • API Gateway (PrivateLink)
  • CloudWatch (Logs, Monitoring, Events)
  • SQS, SNS, EventBridge
  • KMS, Secrets Manager, Systems Manager
  • ECR, ECS, EKS
  • STS
  • Lambda (invoke endpoint)
  • DynamoDB also has an Interface endpoint (new — pick 1 of the 2)
  • SageMaker, Bedrock
  • ...

Note: S3 Interface Endpoint

  • AWS added an Interface Endpoint for S3 (in addition to Gateway)
  • When to use Interface for S3?
    • Accessing S3 from on-prem via Direct Connect/VPN (Gateway cannot be routed from on-prem)
    • Cross-VPC via Transit Gateway accessing a shared S3 endpoint
  • Default: use the 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"
      }
    }
  }]
}

→ The bucket is only accessible from this VPC via the specific endpoint.

8. Decision: VPC Endpoint vs NAT Gateway

SituationRecommendation
EC2 private subnet accesses only S3 + DynamoDBGateway Endpoints (free), no NAT GW needed if there is no other internet access
EC2 accesses multiple AWS services + internetNAT GW + Interface Endpoints for services with large data volumes
Data transfer to S3 > 10 GB/monthGateway Endpoint, definitely
Need access 3rd-party SaaS via PrivateLinkPrivateLink Interface Endpoint
Strict compliance: no internetEndpoints for every service + No NAT GW

9. Cost Optimization with Endpoints

Strategies

  1. S3 Gateway Endpoint (always use it — free + reduces NAT cost)
  2. DynamoDB Gateway Endpoint
  3. Interface Endpoints for services with > 10 GB/month data
  4. Consolidate AZs for Interface Endpoints (each AZ adds $0.01/hour)
  5. Endpoint Policy restrictions to avoid leaking through

Common high-cost services via NAT

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

Part 2: VPN and Direct Connect Intro

1. Hybrid Connectivity Overview

Hybrid use cases (on-prem + AWS)

  • Migration (gradual lift-and-shift)
  • Data sync between the on-prem DC and AWS
  • Burst compute to AWS from on-prem
  • DR (AWS as DR for on-prem)
  • Compliance (sensitive data on-prem, app on AWS)

Options

OptionBandwidthLatencyCostEncryptedSetup time
Site-to-Site VPN~1.25 Gbps/tunnelVariable (internet)$Yes (IPsec)Minutes
Direct Connect1, 10, 100 Gbps dedicatedStable, low$$$No (over DX)Weeks - months
DX + VPNSame as DXSame as DX$$$YesWeeks
Client VPNPer-userVariable$/user-hourYesMinutes
Transit Gateway + DX/VPNAggregateSame$$Depends—

2. Site-to-Site VPN

Definition

Site-to-Site VPN = an IPsec tunnel between the on-prem router (Customer Gateway) and an 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)
  • Represents the on-prem device in AWS
  • Public IP of the on-prem router (or NAT IP)
  • BGP ASN (if using dynamic routing)
Virtual Private Gateway (VGW)
  • AWS-side endpoint
  • Attached to the VPC
  • HA built-in (2 endpoints)

2 VPN Tunnels per Connection

  • Each VPN connection has 2 tunnels in 2 different AZs (HA)
  • The on-prem router configures both tunnels (active-active or active-passive)

Routing options

  • Static routing: add routes manually
  • Dynamic routing (BGP): AWS and the CGW exchange routes via BGP

Bandwidth

  • Per tunnel: ~1.25 Gbps (single TCP flow)
  • Multi-tunnel ECMP: up to 5 Gbps total (Transit Gateway VPN attachment)
  • Enough for most workloads, not suitable for high-volume data transfer

Setup time

  • Minutes to set up the AWS side
  • Depends on the on-prem router configuration (usually a few hours)

Cost

  • $0.05/hour per VPN connection
  • Data transfer out (AWS → on-prem): charged at standard internet egress rates (~$0.09/GB) — VPN has no separate rate

Use case

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

3. AWS Direct Connect (DX)

Definition

Direct Connect = a dedicated physical fiber connection from on-prem to AWS, not over the internet.

Characteristics

  • Dedicated bandwidth: 1, 10, 100 Gbps
  • Lower latency: predictable, stable (not over the internet)
  • Lower data transfer cost (chargeable at "DX rates")
  • Setup time: weeks - months (physical fiber must be installed)
  • Not encrypted by default (need VPN over DX for encryption)

Setup

  1. Order a DX connection from the AWS Console
  2. Connect the on-prem router → a DX location (1 of 100+ DX POPs worldwide)
  3. Or use a DX Partner (AT&T, Verizon, ...) if you have no physical presence at a DX POP
  4. Configure a Virtual Interface (VIF)

3 types of Virtual Interface (VIF)

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

Direct Connect Gateway

  • Lets 1 DX connection access multiple VPCs in multiple Regions (same account or cross-account)
  • Topology: CGW → DX → DX Gateway → VGW (multiple VPCs)

HA for Direct Connect

  • Single DX connection: NOT HA (single physical link)
  • Best practice:
    • 2 DX connections at 2 different DX locations (max HA)
    • Or 1 DX + VPN backup (cost optimization)

Cost

  • Port hour: $/hour per Gbps port (~$0.30/hour for 1 Gbps)
  • Data transfer out: cheaper than 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

Definition

Client VPN = a managed VPN service for individual user devices (laptop, mobile) to connect to an AWS VPC via an OpenVPN client.

Characteristics

  • TLS-based (OpenVPN)
  • Authentication:
    • Active Directory (via 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 accessing internal apps (alternative to a corporate VPN)
  • Contractor access to specific 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 recommends 3 resilience patterns:

Maximum Resiliency (4 nines+)

  • 2 DX locations, each with 2 connections (4 total)
  • Tolerates location failure + connection failure
  • Highest cost

High Resiliency (3 nines+)

  • 2 DX locations, 1 connection each (2 total)
  • Tolerates location failure
  • Moderate cost

Development & Test

  • 1 DX location, 1 connection
  • NOT HA — accepts downtime if DX fails
    • Backup VPN
  • Low cost

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...
  • A single connection accesses many 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: internet egress rates (~$0.09/GB) — Site-to-Site VPN has no separate rate; DX is the way to reduce 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

Part 3: Amazon Route 53

1. Route 53 Overview

Amazon Route 53 = scalable DNS service + domain registrar + health check.

Characteristics

  • Authoritative DNS (managed by AWS)
  • 100% availability SLA (the only AWS service with a 100% SLA)
  • Global service (anycast routing)
  • Domain registrar (buy/transfer domains)
  • Health check + DNS failover

The name "Route 53"

  • Port 53 = the standard DNS port

2. Quick DNS Concepts Review

DNS Hierarchy

.(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)NOT allowedAllowed ✓
Subdomain (www.example.com)OKOK
TargetAny 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
  • A Route 53 record in the same hosted zone

3. Hosted Zones

Definition

Hosted Zone = a container holding the DNS records for 1 domain.

2 types

  • Public Hosted Zone: resolves over the public internet
  • Private Hosted Zone: resolves only within 1 or more VPCs

Cost

  • $0.50/month per hosted zone (first 25)
  • $0.10/month after 25

Setup public zone

  1. Create a hosted zone for example.com
  2. Route 53 assigns 4 nameservers (ns-1234.awsdns-12.com...)
  3. Update the nameservers at the domain registrar (if bought outside AWS)
  4. Add records (A, AAAA, MX, ...)

Setup private zone

  1. Create a private hosted zone, associate it with a VPC
  2. Records only resolve within that VPC
  3. Use case: internal DNS (db.internal, api.internal)

4. Domain Registrar

Route 53 as Registrar

  • Buy domains directly in Route 53
  • Hosted zone created automatically
  • Auto-renew (configurable)
  • Domain transfer in/out

If the domain was bought elsewhere (GoDaddy, Namecheap...)

  1. Create a hosted zone in R53
  2. Get the 4 nameservers R53 assigns
  3. Update the nameservers at the registrar (GoDaddy, ...)
  4. Wait for DNS propagation (24-48h)

5. 7 Routing Policies

5.1 Simple Routing

  • 1 record, 1 or more values (random select)
  • No health check
  • Default
example.com → A → 1.2.3.4
              → 1.2.3.5     (random pick)

5.2 Weighted Routing

  • Split traffic by % weight
  • Weights do not need to sum to 100
example.com → A → 1.2.3.4 (weight 70)
              → 1.2.3.5 (weight 30)
→ 70% of traffic to .4, 30% to .5
Use case
  • A/B testing
  • Gradual rollout (canary)
  • Multi-region traffic distribution by ratio

5.3 Latency-based Routing

  • Routes users to the Region with the lowest latency from the user's location
  • AWS measures latency in real time
example.com:├──Recordus-east-1→ALB-us-east└──Recordap-southeast-1→ALB-ap-southeastUserVN→Lowestlatencytoap-southeast-1→ALB-ap-southeastUserUS→Lowestlatencytous-east-1→ALB-us-east
Use case
  • Global multi-region app
  • Optimize user experience

5.4 Failover Routing

  • Active-Passive failover
  • Primary record + Secondary record
  • Health check on the primary → if unhealthy, route to the 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

  • Routes based on the user's geographic location (country, continent, default)
  • Differs from latency-based: based on location, not latency
example.com:├──Country=VN→ALBVietnam├──Country=JP→ALBJapan├──Continent=NA→ALBUS└──Default→ALBglobal
Use case
  • Localized content (Vietnamese website for VN users)
  • Compliance (data residency)
  • Restrict access by geography

5.6 Geoproximity Routing (Traffic Flow only)

  • Routes based on geography + bias
  • Bias (-99 to +99) adjusts traffic toward a region
  • Requires 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

  • Returns multiple records (up to 8) in 1 response
  • The client (browser) picks 1 at 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 types

Endpoint health check
  • Monitor an HTTP/HTTPS/TCP endpoint
  • Custom path, port, interval (10s or 30s), failure threshold (3 default)
  • ~15 global locations ping the endpoint
Calculated health check
  • Combine multiple child health checks with AND/OR/NOT
  • Use case: "App healthy if 3+ regions healthy"
CloudWatch alarm health check
  • Trigger a health check based on CloudWatch alarm state
  • Use case: alarm on DynamoDB throttling → DNS failover

Cost

  • Endpoint within AWS: $0.50/check/month (first 50 checks free, same account)
  • Endpoint outside AWS: $0.75/check/month
  • Optional features (HTTPS, string matching, fast interval...): $1-2/feature/month
  • Calculated: $1/check/month
  • CW alarm-based: $1/check/month

DNS failover with health check

  • Add the health check ID to the record
  • If the health check fails → the record is not returned in DNS queries
  • Combine with the Failover routing policy for active-passive

7. Routing Examples

Example 1: Multi-region active-active with failover

example.com(Latency-based):├──LatencyrecordA(us-east-1)+HealthcheckonALB-us-east└──LatencyrecordB(eu-west-1)+HealthcheckonALB-eu-westIfALB-us-eastdown:→R53doesnotreturnrecordA→AllusersroutetoALB-eu-west(stillclosestlatencywise)

Example 2: Blue/Green deployment with weighted

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

Example 3: Geolocation for compliance

api.example.com:├──EUcountries→ALB-eu-west(GDPR-compliant)├──US→ALB-us-east└──Default→ALB-global(withPIIstripping)

8. DNS TTL

Definition

TTL (Time To Live) = how long a DNS resolver caches a 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)
  • Before a migration: lower the TTL 1-2 days ahead so changes propagate fast

9. Route 53 Resolver

Definition

Route 53 Resolver = a managed DNS resolver for the VPC, supports:

  • Resolve AWS resources (S3 endpoint, ALB DNS, ...)
  • Resolve public domains
  • Inbound endpoint: on-prem queries AWS DNS
  • Outbound endpoint: AWS queries 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 resolves on-prem domains
  • On-prem resolves AWS private hosted zones

10. DNSSEC

Definition

DNSSEC (DNS Security Extensions) = sign DNS responses to prevent DNS spoofing.

Route 53 supports

  • Sign hosted zone: enable DNSSEC, R53 manages the KSK (Key Signing Key) in KMS
  • Validate (Resolver feature)

Use case

  • Government, regulated industries
  • High-security domains

Review Questions

  1. Which services does a Gateway Endpoint support? Cost?

    Show answer

    A Gateway Endpoint only supports S3 and DynamoDB. It is completely free (no charge). A Gateway Endpoint is added to the route table as a prefix list entry — traffic to S3/DynamoDB routes over the AWS network instead of the internet, without going through the NAT Gateway (saving the NAT GW data processing fee of $0.045/GB).

  2. Does an Interface Endpoint create an ENI? Does it consume private IPs?

    Show answer

    Yes — an Interface Endpoint creates an ENI (Elastic Network Interface) in the specified subnet, with a private IP from the subnet CIDR. It consumes 1 private IP per AZ per service. Interface Endpoints are charged: ~$0.01/hour per AZ + $0.01/GB data processed. They support most AWS services (EC2, SSM, SNS, SQS, Kinesis, API Gateway...) and custom services via PrivateLink.

  3. How does PrivateLink differ from an Interface Endpoint?

    Show answer

    An Interface Endpoint is the consumer side (in your VPC) that uses PrivateLink to access AWS services or 3rd-party services. AWS PrivateLink is the technology/framework behind it — it lets service providers (AWS or you) expose services via an NLB, and consumers access them through an Interface Endpoint. PrivateLink = the technology; Interface Endpoint = the implementation the consumer uses.

  4. To force an S3 bucket to be accessible only from a specific VPC Endpoint, which condition do you use?

    Show answer

    Use the aws:SourceVpce condition in the S3 Bucket Policy: "Condition": {"StringEquals": {"aws:SourceVpce": "vpce-xxxxxx"}}. Or use aws:SourceVpc to allow the whole VPC. Combine with a Deny rule: "Effect": "Deny", "Condition": {"StringNotEquals": {"aws:SourceVpce": "vpce-xxx"}} — this only allows access from the specific endpoint and blocks all other access, including via the internet.

  5. When should you use a VPC Endpoint instead of a NAT Gateway?

    Show answer

    When there is traffic to AWS services (S3, DynamoDB, SSM, SQS...) from a private subnet. Reasons: (1) Security — traffic does not cross the public internet, (2) Cost — Gateway Endpoints are free, and Interface Endpoints are cheaper than a NAT GW for large traffic volumes, (3) Latency — a direct private network path. A NAT Gateway is still needed for internet access (non-AWS destinations). The best pattern: VPC Endpoints for AWS services + NAT GW for regular internet traffic.

  6. What is the Site-to-Site VPN bandwidth per tunnel?

    Show answer

    Each Site-to-Site VPN tunnel supports up to 1.25 Gbps. Each VPN connection has 2 tunnels (HA — if 1 tunnel fails, traffic moves to the other). For higher throughput, you can use Accelerated Site-to-Site VPN (via Global Accelerator) or multiple VPN connections with ECMP on Transit Gateway. Direct Connect provides 1, 10, or 100 Gbps.

  7. Is Direct Connect encrypted by default?

    Show answer

    No — Direct Connect is a dedicated private network connection, but it is not encrypted by default. Data in transit is not encrypted. To encrypt, use MACsec (Layer 2 encryption on the DX connection) or overlay a Site-to-Site VPN over DX (IPSec encryption at Layer 3). For compliance requirements that need encryption in transit, you must implement one of these two layers.

  8. What problem does Direct Connect Gateway solve?

    Show answer

    A DX Gateway lets 1 Direct Connect connection access many VPCs in many Regions (and many AWS accounts). Without a DX Gateway: you need a separate VIF for each VPC. With a DX Gateway: 1 Private VIF connects to the DX Gateway, and the gateway forwards to many VGWs (Virtual Private Gateways) in different VPCs — a hub-and-spoke model for Direct Connect.

  9. Which VIF do you use to access S3 via DX?

    Show answer

    Public VIF (Public Virtual Interface). S3 is a public AWS service with public IPs — you need a Public VIF to access it via DX. A Private VIF only accesses resources in the VPC private IP space. A Transit VIF is used with Transit Gateway. Note: although it is called a "Public" VIF, traffic still goes over the DX connection (not the internet) — more secure, and no internet data transfer charge.

  10. What is the difference between Client VPN and Site-to-Site VPN?

Show answer

Site-to-Site VPN: a network-to-network connection — the entire on-premises network connects to the AWS VPC via a VGW and a Customer Gateway. Used for offices or datacenters that need a persistent connection to AWS. Client VPN: connects an individual device (laptop, remote worker) to the AWS VPC via an OpenVPN client. Each user needs client software and a certificate. Used for remote workers who need access to AWS resources.

  1. What is the difference between CNAME and ALIAS? Can they be used at the apex domain?
Show answer

CNAME: DNS standard, maps a hostname → another hostname, cannot be used at the apex domain (root domain example.com). Queries are charged. ALIAS: a Route 53 extension, maps a hostname → an AWS resource (ALB, CloudFront, S3 website, API GW, Elastic Beanstalk), can be used at the apex domain, no separate query charge, supports health checks. Always use ALIAS instead of CNAME when the target is an AWS service.

  1. How do Latency-based and Geolocation routing differ?
Show answer

Latency-based: Route 53 measures the latency from the user to each AWS Region and routes to the Region with the lowest latency. A user in Vietnam may be routed to Tokyo if that is fastest. Geolocation: routes based on the user's physical location (country, continent) — a user from Vietnam always goes to a specific server regardless of latency. Use Geolocation for compliance (data residency) and localization; use Latency for the best performance.

  1. What does Failover routing require for the primary record?
Show answer

The primary record must have an associated Health Check. Route 53 monitors the endpoint via the health check — when the primary fails (health check fails), it automatically fails over to the secondary record. The secondary record does not need a health check (but it is best practice to have one). Health checks can monitor HTTP/HTTPS endpoints, TCP ports, or CloudWatch alarms.

  1. What is the maximum number of records Multivalue Answer routing returns?
Show answer

8 records (maximum). Multivalue Answer returns multiple IP addresses for the same hostname and only returns healthy records (requires a health check per record). Unlike Simple routing: Simple has no health check filtering. It cannot replace a Load Balancer (DNS round-robin is not perfect), but it is a simple solution for distributed/multi-region setups that don't need an ALB.

  1. What is a Route 53 Resolver Inbound Endpoint used for?
Show answer

It lets on-premises DNS servers forward DNS queries to the Route 53 Resolver (to resolve AWS internal hostnames such as VPC private zones and RDS endpoints). The Inbound Endpoint creates ENIs in the VPC — on-premises DNS queries go to the ENI IPs, and Route 53 resolves them and returns the result. Conversely, an Outbound Endpoint forwards DNS queries from the VPC out to on-premises DNS servers.

Hands-on Exercises

  • Create a Gateway Endpoint for S3 in the VPC, observe the route table change
  • Test EC2 in a private subnet (no NAT GW) accessing S3 via the endpoint
  • Create an Interface Endpoint for SQS with Private DNS enabled
  • Apply an endpoint policy restricting the S3 endpoint to 1 bucket only
  • Set up PrivateLink: create an NLB + Endpoint Service in 1 VPC, consume it from another VPC

Part 2: VPN and Direct Connect Intro

  • Set up a Site-to-Site VPN with a simulated CGW (pfSense on EC2 in another VPC or a test environment)
  • Create a Client VPN endpoint with mutual TLS, test connecting from a laptop
  • Draw a hybrid architecture diagram: an on-prem DC connecting to 3 AWS VPCs in different Regions
  • Compare cost: VPN vs DX 1 Gbps for 1 TB data/month

Part 3: Amazon Route 53

  • Create a Public Hosted Zone for a domain (you can use a free .tk domain or a subdomain)
  • Add an A record with Simple routing pointing to 1 EC2 instance
  • Create Weighted routing: 80/20 split for A/B testing
  • Set up Failover routing with a health check on an ALB
  • Create a Private Hosted Zone, associate it with a VPC, test resolving an internal name
  • Set up a Route 53 Resolver Inbound endpoint (advanced)

References


Next lesson →