What is a VPC?
Your own private section of AWS's network.
Part 1: The problem
QuickCart’s first backend was a single server with a public internet address. The API that the app talks to ran on it, and so did the database holding every order.
The app only ever needed to reach the API. Nothing outside ever needed to reach the database directly. But because the whole server faced the internet, anyone could try.
So QuickCart needs two things at once:
- The app can reach the API, from anywhere in the world.
- Nobody can reach the database — except the API.
A VPC is how you get both.
Part 2: The idea
A VPC — Virtual Private Cloud — is a private section of AWS’s network that belongs to your account. Other AWS customers can’t see into it, and the internet can’t reach anything inside it unless you open a way in.
It starts with a range of addresses
Every server in a VPC gets an internal address, like 10.0.11.24. When you create the VPC, you choose the range those addresses come from, written like 10.0.0.0/16. This way of writing a range is called CIDR.
| You write | It means | How many addresses |
|---|---|---|
10.0.0.0/16 | every address from 10.0.0.0 to 10.0.255.255 | 65,536 |
10.0.1.0/24 | every address from 10.0.1.0 to 10.0.1.255 | 256 |
10.0.1.0/28 | 10.0.1.0 to 10.0.1.15 | 16 |
The number after the slash is how many bits of the address are fixed. A smaller number means a bigger range. You don’t need to do the maths by hand yet — remember that /16 is big and /24 is small. The subnets lesson goes further.
Then you slice it into subnets
A subnet is a slice of the VPC’s range. Each subnet lives in exactly one availability zone — one physical data centre site. QuickCart’s VPC gets three kinds:
| Subnet | Range | What lives there | Reachable from the internet? |
|---|---|---|---|
| Public | 10.0.1.0/24 | The load balancer — the front door | Yes |
| App | 10.0.11.0/24 | The API servers | No |
| Database | 10.0.21.0/24 | The database | No |
What makes a subnet public or private
This is the part people get wrong. There is no setting called public. Every subnet has a route table — a short list of rules saying where traffic goes. One line decides everything:
| The route table says | So the subnet is |
|---|---|
0.0.0.0/0 → internet gateway | Public. Traffic can come in from, and go out to, the internet |
0.0.0.0/0 → NAT gateway | Private. It can reach out — to download updates — but nothing can reach in |
no 0.0.0.0/0 line at all | Isolated. It can only talk to things inside the VPC |
0.0.0.0/0 means anywhere I don’t have a more specific rule for — in practice, the internet.
The pieces, in one table
| Piece | What it is | QuickCart uses it for |
|---|---|---|
| VPC | The whole private network | Everything lives inside it |
| Subnet | A slice of it, in one zone | Keeping the database away from the internet |
| Route table | The rules for where traffic goes | Deciding which subnets are public |
| Internet gateway | The door to the internet | Letting customers reach the load balancer |
| NAT gateway | A one-way door out | API servers downloading updates, with nothing getting in |
Everything inside the VPC can still talk to everything else inside it, through a route called local that every route table has and you can’t remove. That is how the API reaches the database: the database is unreachable from the internet, but not from its neighbours.
Part 3: See it
Below is QuickCart’s network. Send an order from the app and watch the path it takes. Then send an attack straight at the database. Switch the database subnet between private and public and try again.
What to notice: nothing about the database changed between the two attacks — not the server, not the password. Only one line in one route table. That is why the route table is the first thing to check when something is, or isn’t, reachable.
Part 4: Do it
Free — nothing in this lab costs money.
You’ll build a small version of QuickCart’s network in the AWS console: a VPC, one public subnet, one private subnet, and the route that makes the difference. It takes about 15 minutes.
Before you start, check the region selector at the top right of the console says N. Virginia (us-east-1). Everything in this lab goes in that region.
Create the VPC
In the AWS console: VPCYour VPCsCreate VPC
Field Enter Resources to create VPC only Name tag quickcart-vpcIPv4 CIDR block IPv4 CIDR manual input IPv4 CIDR 10.0.0.0/16IPv6 CIDR block No IPv6 CIDR block Tenancy Default Choose Create VPC.
You should seeThe VPC’s details page, with State: Available.
Create two subnets
In the AWS console: VPCSubnetsCreate subnet
For VPC ID, choose
quickcart-vpc. Then fill in the first subnet, choose Add new subnet, and fill in the second:Subnet name Availability Zone IPv4 subnet CIDR block quickcart-public-aus-east-1a 10.0.1.0/24quickcart-app-aus-east-1a 10.0.11.0/24Choose Create subnet.
You should seeTwo subnets in the list. Right now both are private — neither has a route to the internet yet.
Create the internet gateway and attach it
In the AWS console: VPCInternet gatewaysCreate internet gateway
Field Enter Name tag quickcart-igwChoose Create internet gateway. Then choose Actions → Attach to VPC, pick
quickcart-vpc, and choose Attach internet gateway.You should seeState: Attached. On its own this makes nothing public — no subnet is using the gateway yet.
Make the public subnet public
In the AWS console: VPCRoute tablesCreate route table
Field Enter Name quickcart-rt-publicVPC quickcart-vpcChoose Create route table. On its Routes tab, choose Edit routes, then Add route:
Destination Target 0.0.0.0/0Internet Gateway, then quickcart-igwChoose Save changes. Then open the Subnet associations tab, choose Edit subnet associations, tick
quickcart-public-a, and choose Save associations.You should seeThe route table lists two routes:
10.0.0.0/16 → localand0.0.0.0/0 → igw-…. One subnet is associated. That subnet is now public. You changed a route table; you never touched the subnet itself.Confirm the other subnet is still private
In the AWS console: VPCSubnetsquickcart-app-aRoute table
You should seeOnly one route:
10.0.0.0/16 → local. No way to the internet. The subnet is private because of what is missing.See the whole thing as a map
In the AWS console: VPCYour VPCsquickcart-vpcResource map
You should seeA diagram:
quickcart-public-ajoined toquickcart-rt-public, which joins toquickcart-igw.quickcart-app-ajoins to the VPC’s main route table, which goes nowhere outside.Clean-up step: Clean up
In the AWS console: VPCYour VPCsquickcart-vpcActionsDelete VPC
AWS lists everything that will go with it: the subnets, the route table and the internet gateway. Type
deletein the box and choose Delete.You should seeThe VPC is gone from the list, along with everything inside it. Nothing is left running.
Part 5: Check yourself
What makes a subnet public?
Where should QuickCart's database go?
API servers in a private subnet need to download security updates. What lets them reach out without letting anything reach in?
How many addresses does 10.0.0.0/16 contain?
How many availability zones does one subnet live in?
Part 6: Cheat sheet
| Term | In one line |
|---|---|
| VPC | Your private network on AWS. Closed by default |
| Subnet | A slice of the VPC, in one availability zone |
| Route table | The rules for where a subnet’s traffic goes |
| Public subnet | Route table sends 0.0.0.0/0 to the internet gateway |
| Private subnet | Route table sends 0.0.0.0/0 to a NAT gateway — out only |
| Isolated subnet | No 0.0.0.0/0 route at all |
local route | Always there. Everything in the VPC can reach everything else |
/16 and /24 | 65,536 addresses and 256 addresses |
| Can’t reach something? | Check the route table first |