π§ 1. What is a VPC?
A VPC (Virtual Private Cloud) is your own private network inside AWS.
You control everything β IP ranges, subnets, routing, and security.
Think of it like your own house inside AWS.
Each room (subnet) has a specific purpose β one for guests (public), one for personal use (private).
π§© 2. Key Components of VPC
1. CIDR Block
- Defines your VPCβs IP address range.
- Example:
10.0.0.0/16β gives you 65,536 IPs. - Smaller subnets (like
/24) have 256 IPs. - You canβt overlap CIDR blocks if you want VPC peering later.
2. Subnets
- Subnets divide your VPC into smaller networks.
- Each subnet lives in one Availability Zone only.
- Public Subnet: has internet access (for web servers).
- Private Subnet: internal use only (for DBs, backend services).
3. Internet Gateway (IGW)
- A gateway that lets instances in public subnets access the internet.
- Without it, even public instances canβt reach outside.
Example flow:
Public EC2 β Route Table β IGW β Internet
4. NAT Gateway / NAT Instance
- Used by private subnets to reach the internet without being exposed.
- Example: private EC2 downloading OS updates.
- NAT Gateway sits in the public subnet and routes traffic for private ones.
5. Route Tables
- Define where network traffic should go.
- Each subnet must be associated with one route table.
- Example:
- Public subnet β route to IGW (
0.0.0.0/0 β IGW) - Private subnet β route to NAT (
0.0.0.0/0 β NAT GW)
- Public subnet β route to IGW (
6. Security Groups (SGs)
- Instance-level firewalls.
- Control inbound and outbound traffic.
- Stateful: if inbound is allowed, return traffic is automatically allowed.
7. Network ACLs (NACLs)
-
Subnet-level firewalls.
-
Stateless: need to define inbound and outbound separately.
-
Add an extra layer of protection to your network.
8. VPC Peering
-
Connects two VPCs privately (no internet in between).
-
Works only for non-overlapping CIDR blocks.
-
Not transitive: AβB and BβC doesnβt mean AβC.
9. VPC Endpoints
-
Connect AWS services (like S3, DynamoDB) privately without using the internet.
-
Two types:
-
Gateway Endpoint: for S3, DynamoDB.
-
Interface Endpoint: for most other services.
-
10. VPC Flow Logs
-
Capture network traffic logs in your VPC.
-
Useful for debugging and auditing.
-
Logs go to CloudWatch or S3.
-
Note: they donβt log DNS or Windows license traffic.
π§° 3. Default vs Custom VPC
| Feature | Default VPC | Custom VPC |
|---|---|---|
| Automatically created | β Yes | β No |
| Internet access ready | β Yes | β Manual setup |
| Subnets | 1 per AZ | You decide |
| Route tables, IGW | Preconfigured | You configure |
| Best for | Testing or learning | Production |
Default VPC is plug-and-play, but custom VPC gives full control and security.
π§ 4. Analogy for Easy Understanding
| Concept | Analogy |
|---|---|
| VPC | Your house |
| Subnet | Each room in the house |
| Route Table | Directions board for where to go |
| Internet Gateway | Main door (to the outside world) |
| NAT Gateway | Secret door β you can go out, but no one can come in |
| Security Group | Door lock on a specific room |
| NACL | Boundary wall around the house |
π 5. AWS Associate Exam Tips
-
Subnets = 1 AZ only (they canβt span across AZs).
-
NAT Gateway must be in public subnet.
-
Security Groups = Stateful, NACLs = Stateless.
-
Default NACL allows everything in/out.
-
VPC Peering isnβt transitive.
-
VPC CIDR blocks canβt overlap for peering.
-
Flow logs donβt record DNS or Windows license traffic.
-
IGW is required for public internet access.
βοΈ 6. Example Architecture
VPC: 10.0.0.0/16
β
βββ Public Subnet (10.0.1.0/24)
β βββ EC2 Instance (Web Server)
β βββ Route β IGW
β
βββ Private Subnet (10.0.2.0/24)
β βββ EC2 Instance (App Server)
β βββ Route β NAT Gateway β IGW
β
βββ Security:
βββ SG: Allow HTTP (80), SSH (22)
βββ NACL: Allow inbound 80, outbound 443
π‘ Bonus (for real-world + exam)
-
Always have at least two subnets in different AZs for high availability.
-
For production, place DBs in private subnets.
-
Use VPC Endpoints instead of public S3 access for better security.
-
Use Flow Logs + CloudWatch to monitor traffic patterns.
If you want, I can make a clean Excalidraw diagram of this architecture (public/private subnet, NAT, IGW, etc.)
Would you like me to make that visual next?
Also, I can prepare a set of 15 VPC-based AWS exam questions with explanations β perfect for practice before your certification. Want that too?