Virtual Private Cloud (VPC) Basics

IP Subnetting

Subnetting – Key Concepts
Subnetting Process Step by Step
Designing Business Networks and IP Plans

Building a reliable infrastructure platform depends as much on strong design decisions as it does on technical implementation.

Considerations when Designing Business Networks

VPC Sizing and Structuring – Concepts

VPC Size (CIDR)

VPC Structure (Subnets)

VPC Sizing and Structuring – Example

VPC Sizing & Structuring – Considerations
VPC Design for A4L Scenario

Amazon VPC (Virtual Private Cloud) 101

Amazon VPC – Core Concepts
Default VPC

Custom VPCs

Amazon VPC – Refresher
Amazon VPC – Custom VPCs
Custom VPC IP Addressing (Quotas)

IPv4

IPv6

DNS in VPCs
Demo: Custom VPC Design (Course Scenario)

VPC Subnets & DHCP Options Set

VPC Subnets – Core Concepts
VPC Subnets – IP Addressing
DHCP Options Set

Network Address Translation (NAT)

NAT – Core Concepts
Types of NAT

Static NAT

Dynamic NAT

Port Address Translation (PAT)

(also known as IP masquerading or NAT overload)

VPC Routing, Internet Gateway & Bastion Hosts

VPC Router

VPC Route Table (RT)

Internet Gateway (IGW)

IPv4 Behavior with IGW

IPv6 Behavior

Bastion Host / Jump Box

NAT Gateways & NAT Instances

Common Scenario: Updating Private EC2 Instances
  1. Convert the subnet to public
    • Allows direct internet access for instances
    • Drawback: breaks standard secure multi-tier architecture design, where private subnets are intentionally isolated
  2. Maintain internal update servers
    • Host patch repositories within the VPC
    • Drawback: introduces operational overhead
      • Requires manually downloading updates and distributing them internally
  3. Recommended approach: use NAT (Network Address Translation)
    • Enables private instances to access the internet without becoming publicly accessible
    • Deployment options:
      • NAT Instance (self-managed EC2)
      • NAT Gateway (NATGW) (AWS-managed service)
Refresher: Network Address Translation (NAT)

NAT Types

  1. Static NAT
    • One private IP maps to one public IP
    • Used by Internet Gateway (IGW)
  2. Dynamic NAT
    • Multiple private IPs share a pool of public IPs
  3. Port Address Translation (PAT)
    • Many private IPs share a single public IP
    • Differentiation handled via port numbers
    • Also known as IP masquerading
    • Most commonly used form of NAT in practice
NAT Architecture in a VPC

Traffic Flow

  1. Private subnet sends traffic to NATGW
    • Route table default route (0.0.0.0/0) points to NATGW
    • NATGW records sessions in a translation table
  2. NATGW modifies source IP
    • Replaces private IP with its own private IP
  3. Traffic is forwarded to Internet Gateway (IGW)
    • Via the VPC router
  4. IGW performs final translation
    • Replaces NATGW private IP with a public IP
  5. Return traffic follows reverse path
    • IGW → NATGW → private instance
NAT Gateway (NATGW) – Key Concepts

Characteristics

Limitations

Billing Model

NAT Instances

Special Configuration

NAT Instances vs NAT Gateway

Why NAT Gateway is the default choice

When NAT Instances may be preferred

  1. Cost considerations
    • Lower cost for:
      • Small environments
      • Low traffic workloads
    • Can use small or free-tier instances
    • Predictable pricing (fixed instance size)
  2. Multi-purpose usage
    • Can act as:
      • Bastion host
      • Port forwarding device
    • NATGW cannot be customized
  3. Security flexibility
    • Supports Security Groups and NACLs
    • NATGW supports only NACLs
IPv6 Considerations

Connectivity Options

Stateless vs Stateful Firewalls

TCP Connections, Ports, and Direction
Stateless Firewall
Stateful Firewall

Network Access Control Lists (NACLs)

VPC NACL – Key Concepts
NACL Rules
NACL Types

Default NACL

Custom NACL

Security Groups (SGs)

VPC Security Group (SG) – Key Concepts
VPC SG – Logical References
SG Self-References

Advanced VPC Networking

VPC Flow Logs
Flow Log Records

Egress-Only Internet Gateway (EIGW)

Differences Between IPv4 and IPv6 in AWS

Network Address Translation (NAT) for IPv4

Egress-Only Internet Gateway (EIGW)

VPC Endpoints (VPCEs) – Gateway & Interface Types

VPC Endpoints (VPCEs)
VPC Gateway Endpoints (GWEs)
Comparison: Access to S3 With and Without GWE

Without GWE

With GWE

VPC Interface Endpoints (IEs)
Comparison: Access to SNS With and Without IE

Without IE

Without IE (without private DNS)

With IE (with private DNS)

Comparison: Gateway Endpoints vs Interface Endpoints
Gateway Endpoint (GWE)Interface Endpoint (IE)
Implemented as a gateway resource within the VPCImplemented as an Elastic Network Interface (ENI) inside a subnet
Used specifically for S3 and DynamoDB servicesUsed for most AWS public services except DynamoDB
Supports both IPv4 and IPv6, along with TCP and UDP protocolsSupports only IPv4 and TCP
Highly available across the region by defaultRequires one endpoint per Availability Zone to achieve high availability
Does not support Security Groups for controlling trafficSupports Security Groups for network access control
Does not rely on PrivateLinkBuilt on AWS PrivateLink technology
Access is controlled via route tables (prefix lists added to routes)Accessed through DNS resolution within the VPC (assigned a private IPv4 address)
No changes needed in application configurationMay require application updates depending on DNS setup (unless Private DNS is used)
Cannot be used for cross-region access to S3 or DynamoDBCan be used to access services across different regions
DEMO: VPCEs (IE, GWE) and EIGW
PART 1: Create a VPC Interface Endpoint (IE) to use Instance Connect on a private EC2 instance
  1. EC2 instance is in private subnet sn-app-A. By default, we cannot connect via Instance Connect since it has no public IP.
  2. Create a VPC IE in sn-app-A via:
    • Instance Connect UI → “EC2 Instance Connect Endpoint”
    • Or directly via VPC → Endpoints
    • Option: Preserve Client IP
      • Enabled → instance sees your machine’s IP
      • Disabled → instance sees the IP of the endpoint’s ENI
  3. Once the endpoint is created, Instance Connect can access the private instance.
    • If client IP is not preserved, the instance shows the endpoint ENI IP in the last login info.
PART 2: Create a VPC Gateway Endpoint (GWE) to access S3 privately
  1. Private instance in sn-app-A cannot access the public internet or S3.
    • ping 1.1.1.1 fails
    • aws s3 ls shows nothing
  2. Create a GWE for S3:
    • VPC → Endpoints → Create Endpoint → Type: AWS Services → filter by s3 → Gateway type
    • Select the main route tables for private subnets (sn-app-A)

3. Once the GWE is created, private instance can access S3:

4. Instance remains private: ping 1.1.1.1 still fails

PART 3: Create an Egress-only Internet Gateway (EIGW) for a private IPv6 instance
  1. EC2 instance in sn-app-A has an IPv6 address but cannot reach the internet
    • ping -6 ipv6.google.com fails
  2. Create an EIGW:
    • VPC → Egress-only Internet Gateway → Create → Attach to A4L-VPC
  3. Update the Route Table for main subnets:

4. Verify IPv6 connectivity:

5. Optional test: confirm another EC2 instance in a different VPC cannot ping this IPv6 instance.

VPC Peering

VPC Peering – Concepts and Features
DEMO: Peering 3 VPCs
  1. Start with three private VPCs, one EC2 instance in each.
    • Connect via Session Manager to EC2 in VPCA
  2. Ping instance in VPCB → no response (private VPCs by default)
  3. Create peering between VPCA and VPCB
    • VPC → Peering connections → Create → VPCA as sender, VPCB as accepter
    • Invitation model: accepter must accept the request
    • Peering remains in Pending state until accepted
  4. Update Route Tables in both VPCA and VPCB
    • Add route → destination = other VPC’s CIDR → target = peering object
  5. Update Security Groups
    • Add inbound rules to allow ICMP/IPv4 traffic from the other VPC’s SG
  6. Ping between VPCA and VPCB instances should now succeed
  7. Repeat steps 3–6 to create peering between VPCB and VPCC
  8. Attempt A → C ping → fails
    • VPC peering is not transitive; a direct peering between VPCA and VPCC is required
  9. Create peering between VPCA and VPCC
    • Ping from VPCA to VPCC now works

Route 53 – Global DNS

Amazon R53 (Route 53) 101

Amazon Route 53 (R53) – Key Concepts
R53 Registered Domains

Domain registration workflow (e.g., animals4life.org):

  1. Check if domain is available
  2. Accept terms and purchase the domain
  3. R53 creates a ZoneFile (database storing DNS info)
  4. R53 allocates four AWS-managed name servers (NSs) for this domain
  5. Creates a hosted zone with the ZoneFile, storing it on the four NSs
  6. R53 communicates with the TLD (e.g., PIR)
    • TLD NS records point to R53’s four servers → these become authoritative
R53 Hosted Zones

Network visibility types:

  1. Public Hosted Zones – accessible from the internet
  2. Private Hosted Zones – linked to one or more VPCs, only accessible from those VPCs

Billing:

R53 Public and Private Hosted Zones

R53 Public Hosted Zone
R53 Private Hosted Zone
Split-View (Split-Horizon) DNS

CNAME Records vs R53 Alias Records

Limitations of CNAME Records
Route 53 Alias Records

Key guideline:

Use CNAME for subdomains. Use Alias records for apex/naked domains or when pointing to AWS-managed services.

R53 Simple Routing Policy

Route 53 Routing Policies Overview
Route 53 Simple Routing

R53 Health Checks

Route 53 Health Checks Overview
Endpoint Health Checks – Configuration

Basic options:

Advanced options:

Health Check Notifications

R53 Failover Routing Policy

Route 53 Failover Routing – Architecture

This architecture ensures minimal downtime and transparent failover at the DNS level.

DEMO: Setting Up Route 53 Hosted Zones and Routing Policies

Part A – Implementing a Route 53 Failover Routing Policy

Step 1: Create a Health Check for the Primary Resource

  1. Navigate to Route 53 → Health Checks → Create Health Check.
  2. Configure an endpoint health check for your primary EC2 application:
    • Endpoint can be specified by public IP or DNS name.
    • If using IP, assign an Elastic IP to ensure a static address even if the instance restarts or experiences issues.
  3. Health checks initially start in an unknown state and require some time to evaluate the endpoint before marking it healthy or unhealthy.

Step 2: Create Primary and Secondary Failover Records

Go to Route 53 → Hosted Zones → <YOUR_HOSTED_ZONE> → Create Record.

Configure primary failover record:

Configure secondary failover record:

Both records should now exist, with the primary record linked to its health check.

Step 3: Validate Failover

  1. Simulate failure by stopping the EC2 instance.
    • After a few minutes, traffic should automatically resolve to the secondary (S3) resource.
  2. Restart the EC2 instance to simulate recovery.
    • After propagation, traffic should resolve back to the primary EC2 resource.
Part B – Configuring a Private Hosted Zone

Create a private hosted zone:

Associate the hosted zone with the target VPC(s):

Define DNS records as needed (e.g., A records pointing to private IPs).

Test resolution by pinging the record’s IP from an EC2 instance inside an associated VPC.

R53 Multivalue Answer Routing Policy

Route 53 Multivalue Answer Routing – Architecture

R53 Weighted Routing Policy

Route 53 Weighted Routing – Architecture

R53 Latency Routing Policy

Route 53 Latency Routing – Architecture

Route 53 Geolocation-Based Routing

Route 53 Geolocation Routing – Architecture
Client locationRecord returned
Houston, Texas, USATexas
Sacramento, California, USAUnited States
Buenos Aires, ArgentinaArgentina
Porto Alegre, RS, BrazilSouth America
Toronto, Ontario, CanadaNo Answer
Munich, Bavaria, GermanyEurope
Tokyo, JapanNo Answer
Brisbane, Queensland, AustraliaNo Answer

Route 53 Geoproximity-Based Routing

Route 53 Geoproximity Routing – Architecture

Route 53 Routing Policies – Overview

Policies with 1–2 records per hostname (basic routing strategies)
Route 53 Routing PolicyDesignReturned RecordsTypical Use Cases
Simple– Single DNS record per hostname, may include multiple IP values
– No health monitoring configured
All record values are provided to the client in a non-deterministic order; the client selects which one to use– Direct traffic to a single application endpoint (e.g., web server)
– Straightforward and low-maintenance setup
Failover– Two DNS records sharing the same hostname: primary and standby
– Health check applied to the primary endpoint
– If the primary endpoint is healthy → return primary record
– If the primary endpoint fails → return secondary record
– Active-passive disaster recovery setup
– Useful for fallback scenarios like outages or maintenance pages
Policies with multiple records per hostname (advanced routing strategies)
Route 53 Routing PolicyDesignReturned RecordsTypical Use Cases
Multivalue AnswerMultiple DNS records share the same hostname, all treated with equal priorityReturns up to 8 healthy records, selected randomlySupports active-active DNS setups and enhances availability
WeightedEach DNS record is assigned a relative weightHealthy records are returned proportionally based on their assigned weight compared to the total– Gradual traffic shifting (e.g., canary releases)
– Basic traffic distribution across endpoints
LatencyRecords are associated with different AWS RegionsReturns the healthy endpoint with the lowest network latency for the requesterImproves response times and user experience for globally distributed applications
GeolocationRecords are mapped to specific geographic locationsReturns the most precise matching record based on user location (region → country → continent → default)– Deliver region-specific or localized content
– Enforce geographic restrictions
– Route users based on location
GeoproximityRecords are linked to geographic coordinates, with optional bias configurationReturns the closest healthy endpoint to the user, factoring in any configured biasEnables dynamic routing based on physical proximity and traffic shaping preferences

R53 Interoperability

Route 53 – Domain Registrar vs DNS Hosting Provider
Route 53 – Registrar and Hosting Combined
Route 53 – Registrar-Only Setup
Route 53 – Hosting-Only Setup

Implementing DNSSEC using R53

Enabling DNSSEC in an Amazon Route 53 Public Hosted Zone

This section covers the steps to enable DNSSEC for an existing Route 53 public hosted zone.

Step 1: Configure Keys and Signing within the Zone

  1. Key Signing Key (KSK)
    • KMS is used to generate an asymmetric key pair for the KSK.
    • KSK must be created in the us-east-1 region.
    • Route 53 uses the private KSK to sign the DNSKEY records, producing RRSIG records.
  2. Zone Signing Key (ZSK)
    • KMS is not used; Route 53 generates and manages ZSKs internally, including automatic rotation.
  3. DNSKEY Records
    • Public KSK and public ZSK are added to the zone’s DNSKEY records.
    • These records provide the cryptographic basis for DNSSEC validation.

Step 2: Establish Chain of Trust with the Parent Zone

  1. Provide Public KSK to Parent
    • If Route 53 is the registrar, it can automatically send the public KSK to the TLD registry.
    • If using a third-party registrar, the public KSK must be provided manually to the registrar, who updates the parent zone.
  2. Parent Zone DS Records
    • The parent zone stores a hash of the public KSK in its DS records.
    • This establishes trust from the parent zone to the child zone.

Step 3: Monitor DNSSEC Key Health

Step 4: Optional DNSSEC Validation for VPCs

Demonstration: Enabling DNSSEC for animals4life.org

Important: When enabling DNSSEC for a production zone, follow each step in order and allow each change to propagate before continuing. Pay attention to TTL values of domain records.

Step 1: Enable Zone Signing

  1. In the Route 53 public hosted zone, enable DNSSEC.
  2. Create a KSK for the zone, which generates a KMS key internally.
  3. Verify configuration: dig animals4life.org DNSKEY +dnssec
    • If DNSSEC is enabled, the response includes:
      • Public ZSK (flag=256)
      • Public KSK (flag=257)
      • RRSIG for the DNSKEY record
    • If not enabled, no DNSKEY record is returned.

Step 2: Establish Chain of Trust with Parent Zone

  1. Obtain the KSK information from the zone.
  2. In R53 Registered Domains, under DNSSEC, click “Manage Keys” and provide the public KSK.
  3. Verify chain of trust: dig org NS +short # List authoritative NSs for .org
    dig animals4life.org DS @
    • Presence of the DS record confirms the chain of trust.
    • Note: Propagation may take some time depending on TLD registry updates.

Step 3: Secure DNS Records with DNSSEC

Global Content Delivery and Network Optimization

Amazon CloudFront (CF) 101

Latency in Global Applications
Amazon CloudFront – Core Concepts

Key CloudFront Terminology

Key Features of CloudFront

CloudFront Architecture Overview
  1. Application content is stored in an origin (e.g., an S3 bucket).
  2. A CloudFront distribution is configured with the origin.
  3. Content is cached at multiple edge locations worldwide.
  4. Each distribution is assigned a unique domain name ending in cloudfront.net, with optional support for custom domains.
  5. Regional edge caches act as an additional caching layer between edge locations and the origin.

Request Flow

CloudFront Behaviors

Behavior Characteristics

Configuration Scope within Behaviors

CloudFront Distributions and Behaviors – Configuration Settings

CF Distribution-level Settings
CF Behavior-level Settings

CloudFront TTL and Cache Invalidations

CF Caching – Example Scenario
  1. A new image is uploaded to the origin.
  2. User A requests the image. Since it is not yet cached, an origin fetch occurs. The image is stored in the local cache with a defined Time-To-Live (TTL) and then returned to User A.
  3. The image is later updated at the origin, but the cached copy has not yet expired (still considered valid).
  4. User B requests the image. The cached version is served, even though it is now outdated.
    • This highlights a drawback of caching: cached content may become stale.
    • This situation should be minimized where possible, and CloudFront provides mechanisms to handle it.
  5. The cached image eventually expires, but it is not immediately removed—only marked as stale.
  6. User C requests the image. Since the cached version is expired, the request is forwarded to the origin:
    1. If the origin has a new version, it responds with 200 OK and returns the updated image. The cache is refreshed and the new version is delivered to User C.
    2. If the origin has no changes, it responds with 304 Not Modified. The cache marks the object as valid again and resets its TTL.
CF Time-To-Live (TTL) or Validity Period
CF Cache Invalidations

Versioned File Names

SSL/TLS Certificate Management (AWS Certificate Manager)

HTTPS Refresher
AWS Certificate Manager (ACM) – Overview

CloudFront and SSL/TLS Management

SSL in CloudFront
Server Name Indication (SNI)

SNI in CloudFront

SSL & SNI Architecture in CloudFront

CloudFront – Origin Types and Architecture

CloudFront Origins and Origin Groups

Types of Origins

  1. S3 Origins
    • Amazon S3 buckets
    • AWS MediaPackage endpoints
    • AWS MediaStore container endpoints
  2. Custom Origins
    • Any web server (on EC2, on-prem, or elsewhere)

Features and restrictions differ between S3 origins and custom origins.

Common features for all origins:

CloudFront – S3 Origins

Features:

CloudFront – Custom Origins

Features:

CloudFront – S3 Origins vs Custom Origins (Comparison Overview)
S3 OriginsCustom Origins
Amazon S3 buckets, MediaPackage channel endpoints, or MediaStore container endpointsBackend web servers (e.g., EC2, on-premises, or external services)
Minimal setup required, easy to configureOffers more advanced and flexible configuration options
Supports secure access using Origin Access Control (OAC) or legacy Origin Access Identity (OAI)Security typically implemented using custom headers or other mechanisms
Origin protocol policy is always aligned with the viewer protocolOrigin protocol policy can be explicitly set (HTTP only, HTTPS only, or match viewer protocol)
Uses standard HTTP/HTTPS ports by defaultSupports both standard and non-standard (custom) ports
No requirement to define a minimum SSL/TLS version for origin communicationRequires specifying the minimum SSL/TLS protocol version for origin connections

Securing CloudFront Origins

CloudFront Content Delivery Path
Securing S3 Origins

Origin Access Control (OAC) – Recommended

Origin Access Identity (OAI) – Legacy

Securing Custom Origins

LAB: Integrating a CDN with an S3 Static Website

Part 1: Create & Deploy a CloudFront Distribution with S3 Origin
  1. Deploy the provided CloudFormation stack

2. Create a CloudFront distribution

3. Default settings for demo purposes

4. Set the root default object

5. Deploy distribution

Part 2: Test the CloudFront Distribution
  1. Find your default CloudFront domain
    • Ends in cloudfront.net
  2. Open distribution in browser
    • Refresh a few times → pages load quickly (good performance)
    • Caching occurs both at the browser and CloudFront edge location
  3. Modify an object in S3
    • Example: overwrite merlin.jpg (can use a new image, but keep same name)
    • Verify via S3 static website endpoint that the latest version exists
  4. Check CloudFront caching behavior
    • Refresh CF distribution in browser → old image may still appear
    • Browser cache deletion does not bypass edge cache
    • 💡 Updated content is only visible after:
      • Cache TTL expires
      • Or you perform a CloudFront cache invalidation (incurs cost)
  5. Strategies for frequently updated content
    • Reduce object TTL in CloudFront
    • Use versioned object names (merlin_v1.jpg, merlin_v2.jpg)
      • Guarantees latest object served
      • Avoids cache invalidation costs
    • Perform cache invalidation sparingly (costly, generally for error fixes)

6. HTTPS support

Part 3: Add Alternate CNAME & SSL
  1. Requirement: custom domain hosted in Route53
    • Alternatively, follow the demo with placeholder domain
  2. Add alternate domain name (CNAME) in CloudFront distribution

3. Request SSL certificate in ACM

4. Select ACM certificate in CF distribution

5. Create Route53 record

6. Test custom domain

Part 4: Secure the S3 Origin with Origin Access Control (OAC)
  1. Problem: Public S3 bucket
    • By default, the S3 bucket is completely public, allowing all principals.
    • Direct access via S3 static website endpoint bypasses CloudFront, which is not secure.
  2. Configure Origin Access Control (OAC)
    • In CloudFront distribution, change Origin Access from PublicOrigin access control settings
    • Create an OAC with default configuration → CF signs all requests to the S3 origin
    • Copy the generated policy; it will be used in the S3 bucket policy

3. Update S3 bucket policy

4. Test direct S3 access

5. Deploy distribution changes

6. Clean up

CloudFront – Private Distributions and Behaviors

CloudFront – Private Behaviors

Signed URL

Signed Cookie

Example Architecture: Serverless Mobile App with Mixed Behaviors

Request flow:

  1. App requests a resource from CloudFront (public behavior via API Gateway)
  2. When a sensitive image is requested, the Lambda signer validates access
  3. If access is authorized, Lambda generates a signed cookie (using Trusted Key Groups)
  4. Signed cookie and access information are returned to the app
  5. App requests the protected object, sending the signed cookie
  6. CloudFront validates the cookie, fetches the content from the S3 origin, and serves it to the app

CF – Lambda@Edge

CloudFront – Lambda@Edge
Lambda@Edge Architecture

AWS Global Accelerator

Performance Challenges in Single-Region Deployments
AWS Global Accelerator – Core Concepts
CloudFront vs Global Accelerator