Define an isolated virtual network with controlled egress and intra-VPC routing.
VPC = your private neighborhood. Subnets = streets. Route tables = wall-mounted maps. NAT Gateway = the one exit door to the internet.
VPC 10.0.0.0/16
Route Table (per subnet)
- 10.0.0.0/16 -> local
- 0.0.0.0/0 -> igw-... (public) OR nat-... (private)
+-----------------+ +------------------+
| Public Subnet | | Private Subnet |
| 10.0.1.0/24 | | 10.0.10.0/24 |
| NAT, ALB | | App Servers |
+-----------------+ +------------------+
An Amazon VPC is a logically isolated network (CIDR e.g. 10.0.0.0/16). Subnets partition the VPC into /24 (256 IPs) networks in a single AZ. Public subnets route 0.0.0.0/0 to an Internet Gateway (IGW); private subnets route to a NAT Gateway in a public subnet. Each subnet has one route table. For HA, deploy NAT Gateways across AZs; for cost, share one - at the cost of AZ-failure resilience.
aws ec2 create-vpc --cidr-block 10.0.0.0/16
aws ec2 create-subnet --vpc-id vpc-... \
--cidr-block 10.0.1.0/24 --availability-zone us-east-1a
creates a VPC and a /24 subnet in one AZ; repeat for additional AZs.
aws ec2 create-route-table --vpc-id vpc-...
aws ec2 create-route --route-table-id rtb-... \
--destination-cidr-block 0.0.0.0/0 --gateway-id igw-...
creates a public route-table (with IGW) and associates it with a subnet.
aws ec2 allocate-address --domain vpc
aws ec2 create-nat-gateway --subnet-id subnet-public-1a \
--allocation-id eipalloc-...
creates a NAT Gateway (per hour + per GB cost). Place one per AZ for HA.
Putting databases in public subnets ‘because the SG is locked down’. Public subnets are reachable from the internet; risky. Using 192.168.0.0/16 (collides with home networks over VPN).
private subnets for stateful workloads (RDS, ECS tasks); public for ingress only (ALB, NAT, bastion). NAT per AZ in production.
rds-instance-public-access-check flagged it.subnet-tier=private accepted.