Xoxoftware - XOXO Creative Studio | Web & Mobile App Development | Fred Cheung | Hong Kong
AWSNetworking

Amazon VPC

Virtual Private Cloud — isolated network environment covering subnets, route tables, NAT Gateways, NACLs, security groups, VPC endpoints, and peering.

Overview

Amazon Virtual Private Cloud (VPC) is a logically isolated virtual network within AWS — it provides complete control over IP addressing, subnets, route tables, gateways, and network security for AWS resources.

Every AWS account comes with a default VPC in each region. Production workloads should use custom VPCs designed with proper CIDR planning, multi-AZ subnets, and layered security.


Core Concepts

ConceptDescription
VPCA virtual network scoped to a single region; defined by a CIDR block (e.g., 10.0.0.0/16)
SubnetA range of IP addresses within a VPC, scoped to a single AZ; public or private
Route TableRules that determine where network traffic is directed; each subnet is associated with one
Internet Gateway (IGW)Enables internet access for resources in public subnets (horizontally scaled, HA)
NAT GatewayAllows private subnet resources to reach the internet without exposing them to inbound traffic
Security Group (SG)Stateful firewall at the instance/ENI level; allow rules only (implicit deny)
Network ACL (NACL)Stateless firewall at the subnet level; supports allow and deny rules
VPC EndpointPrivate connection to AWS services without traversing the internet
VPC PeeringOne-to-one network connection between two VPCs (same or cross-account/region)
Elastic IP (EIP)Static public IPv4 address allocatable to instances or NAT Gateways

VPC Architecture

Region: us-east-1
┌──────────────────────────────────── VPC (10.0.0.0/16) ────────────────────────────────────┐
│                                                                                            │
│   AZ: us-east-1a                              AZ: us-east-1b                               │
│   ┌─────────────────────┐                     ┌─────────────────────┐                      │
│   │ Public Subnet        │                     │ Public Subnet        │                      │
│   │ 10.0.1.0/24          │                     │ 10.0.3.0/24          │                      │
│   │  ┌──────┐  ┌──────┐ │                     │  ┌──────┐  ┌──────┐ │                      │
│   │  │ ALB  │  │ NAT  │ │                     │  │ ALB  │  │ NAT  │ │                      │
│   │  └──────┘  └──────┘ │                     │  └──────┘  └──────┘ │                      │
│   └─────────────────────┘                     └─────────────────────┘                      │
│   ┌─────────────────────┐                     ┌─────────────────────┐                      │
│   │ Private Subnet (App) │                     │ Private Subnet (App) │                      │
│   │ 10.0.2.0/24          │                     │ 10.0.4.0/24          │                      │
│   │  ┌──────┐            │                     │  ┌──────┐            │                      │
│   │  │ EC2  │            │                     │  │ EC2  │            │                      │
│   │  └──────┘            │                     │  └──────┘            │                      │
│   └─────────────────────┘                     └─────────────────────┘                      │
│   ┌─────────────────────┐                     ┌─────────────────────┐                      │
│   │ Private Subnet (DB)  │                     │ Private Subnet (DB)  │                      │
│   │ 10.0.10.0/24         │                     │ 10.0.11.0/24         │                      │
│   │  ┌──────┐            │                     │  ┌──────┐            │                      │
│   │  │ RDS  │            │                     │  │ RDS  │            │                      │
│   │  └──────┘            │                     │  └──────┘            │                      │
│   └─────────────────────┘                     └─────────────────────┘                      │
│                                                                                            │
│   ┌──────────┐                                                                             │
│   │   IGW    │ ← Internet Gateway (attached to VPC)                                        │
│   └──────────┘                                                                             │
└────────────────────────────────────────────────────────────────────────────────────────────┘

Public vs Private Subnets

AttributePublic SubnetPrivate Subnet
Route to IGWYes (0.0.0.0/0 → igw-xxx)No
Auto-assign public IPTypically enabledDisabled
Internet access (inbound)Possible (via SG rules)Not directly reachable
Internet access (outbound)Direct via IGWVia NAT Gateway in a public subnet
Typical resourcesALB, NAT Gateway, bastion hostsApp servers, databases, internal services

Exam Trap: A subnet is "public" only if its route table has a route to an Internet Gateway and the instances have a public or Elastic IP. Without both, instances cannot reach or be reached from the internet.


NAT Gateway vs NAT Instance

FeatureNAT GatewayNAT Instance
Managed byAWS (fully managed, HA within AZ)Self-managed EC2 instance
BandwidthUp to 100 GbpsDepends on instance type
AvailabilityHA within a single AZ; deploy one per AZSingle point of failure unless scripted
Security groupsNot applicableConfigurable
Bastion hostCannot be used as oneCan double as a bastion
CostPer hour + per GB processedEC2 instance pricing

SAA/SAP Tip: NAT Gateway is the recommended choice for production. Deploy one per AZ for high availability. NAT instances are legacy and only relevant for cost-constrained scenarios or when SG-level filtering on NAT is required.


Security Groups vs NACLs

FeatureSecurity GroupNetwork ACL
LevelInstance / ENISubnet
StateStateful (return traffic auto-allowed)Stateless (return traffic must be explicitly allowed)
RulesAllow only (implicit deny all)Allow and Deny (evaluated in number order)
DefaultDenies all inbound, allows all outboundAllows all inbound and outbound
EvaluationAll rules evaluated before decisionRules evaluated in order; first match wins
Applies toOnly when associated with an instance/ENIAll instances in the associated subnet

Exam Trap: Security Groups are stateful — if inbound traffic is allowed, the response is automatically allowed. NACLs are stateless — both inbound and outbound rules must explicitly permit the traffic, including ephemeral ports.


VPC Endpoints

TypeProtocolUse CaseKey Behaviour
Gateway EndpointS3, DynamoDB onlyAccess S3/DynamoDB without internetFree; add route to route table
Interface EndpointMost AWS servicesPrivate access to AWS APIsCreates ENI in subnet; powered by PrivateLink; charged per hour + per GB

SAA/SAP Tip: Gateway Endpoints for S3 and DynamoDB are free and should always be used in private subnet architectures. Interface Endpoints (PrivateLink) carry hourly + data processing charges but support nearly all AWS services.


VPC Peering

  • Direct network route between two VPCs using private IPs
  • Works cross-account and cross-region
  • Not transitive — if VPC A peers with VPC B and VPC B peers with VPC C, A cannot reach C through B
  • CIDR blocks must not overlap
  • Each peering connection requires route table entries in both VPCs

Transit Gateway

For hub-and-spoke connectivity across many VPCs and on-premises networks:

FeatureVPC PeeringTransit Gateway
TopologyPoint-to-point (mesh)Hub-and-spoke (centralised)
TransitivityNot transitiveTransitive routing supported
ScaleComplex at >5 VPCsSupports thousands of VPCs + VPN/DX
Cross-regionSupportedInter-region peering supported
CostFree (data transfer charges)Per attachment + per GB processed

VPC Flow Logs

Capture IP traffic metadata (not payload) for network interfaces, subnets, or entire VPCs.

  • Destinations: CloudWatch Logs, S3, Kinesis Data Firehose
  • Aggregation intervals: 1 minute or 10 minutes
  • Use cases: troubleshooting connectivity, security analysis, compliance auditing

Common Use Cases

  • Multi-tier web architecture — Public subnets for ALBs, private subnets for app servers, isolated subnets for databases.
  • Hybrid connectivity — Connect on-premises data centres via VPN or Direct Connect through a Transit Gateway.
  • Micro-segmentation — Use security groups and NACLs to enforce least-privilege network access between services.
  • Private AWS API access — Interface Endpoints (PrivateLink) keep traffic off the public internet for compliance.
  • Multi-account networking — Transit Gateway + RAM (Resource Access Manager) for shared network infrastructure.
  • Network compliance — VPC Flow Logs to S3 for audit trails and anomaly detection.

SAA/SAP Exam Tips

SAA/SAP Tip: For problems requiring connectivity across many VPCs (>3), Transit Gateway is the scalable answer. VPC Peering is point-to-point and becomes unmanageable at scale. Transit Gateway also supports transitive routing, which peering does not.

Exam Trap: A Lambda function in a VPC can only access the internet through a NAT Gateway (in a public subnet). Attaching a Lambda to a VPC with no NAT Gateway and no VPC endpoints will cause external API calls and even AWS API calls to fail.

SAA/SAP Tip: For "lowest cost to access S3 from private EC2 instances," the answer is a Gateway Endpoint (free). Interface Endpoints for S3 are charged and should only be used when on-premises access via Direct Connect is required.


Cross-Cloud Equivalents

ProviderService / SolutionNotes
AWSAmazon VPCBaseline
AzureAzure Virtual Network (VNet)Similar concepts; uses NSGs instead of NACLs
GCPGoogle Cloud VPCGlobal VPC model (subnets are regional)
On-PremisesVLANs, pfSense, Cisco routersPhysical network segmentation

Pricing Model

DimensionUnitNotes
VPCFreeNo charge for the VPC itself
NAT GatewayPer hour + per GB processed~$0.045/hr + $0.045/GB (varies by region)
VPC Endpoints (Interface)Per hour + per GB~$0.01/hr per AZ + $0.01/GB
VPC Endpoints (Gateway)FreeNo charge for S3 and DynamoDB gateway endpoints
VPC PeeringPer GB transferredSame-region: $0.01/GB each direction
Transit GatewayPer attachment/hr + per GB~$0.05/hr per attachment + $0.02/GB
Elastic IP (idle)Per hourCharged when not associated with a running instance

Built by Fred Cheung @CookedRicer · Powered by Fumadocs & Github Copilot

On this page