Laptop to Production

What is a VPC?

Your own private section of AWS's network.

Time
25 minutes
Level
Beginner
Read first
Nothing — you can start here

Part 1: The problem

QuickCart, week one

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 writeIt meansHow many addresses
10.0.0.0/16every address from 10.0.0.0 to 10.0.255.25565,536
10.0.1.0/24every address from 10.0.1.0 to 10.0.1.255256
10.0.1.0/2810.0.1.0 to 10.0.1.1516

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:

SubnetRangeWhat lives thereReachable from the internet?
Public10.0.1.0/24The load balancer — the front doorYes
App10.0.11.0/24The API serversNo
Database10.0.21.0/24The databaseNo

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 saysSo the subnet is
0.0.0.0/0 → internet gatewayPublic. Traffic can come in from, and go out to, the internet
0.0.0.0/0 → NAT gatewayPrivate. It can reach out — to download updates — but nothing can reach in
no 0.0.0.0/0 line at allIsolated. 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.

Key point: A subnet is public or private only because of what its route table says. Nothing else.

The pieces, in one table

PieceWhat it isQuickCart uses it for
VPCThe whole private networkEverything lives inside it
SubnetA slice of it, in one zoneKeeping the database away from the internet
Route tableThe rules for where traffic goesDeciding which subnets are public
Internet gatewayThe door to the internetLetting customers reach the load balancer
NAT gatewayA one-way door outAPI 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.

Database subnet
QuickCart's network. On the internet: the QuickCart app and a bot. An internet gateway leads into the VPC. Inside, a public subnet holds the load balancer, a private app subnet holds the API servers, and a database subnet holds the database.The internetQuickCart VPC (10.0.0.0/16)Public subnet0.0.0.0/0 → internet gwLoad balancerthe front doorApp subnet (private)0.0.0.0/0 → NAT gw (out only)API serversthe order serviceDatabase subnetlocal only — no way inDatabaseevery orderQuickCart appa customer's phoneA botscans the internetinternetgateway
ReadyChoose Send an order to follow a request from the app.

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.

  1. Create the VPC

    In the AWS console: VPCYour VPCsCreate VPC

    FieldEnter
    Resources to createVPC only
    Name tagquickcart-vpc
    IPv4 CIDR blockIPv4 CIDR manual input
    IPv4 CIDR10.0.0.0/16
    IPv6 CIDR blockNo IPv6 CIDR block
    TenancyDefault

    Choose Create VPC.

    You should see

    The VPC’s details page, with State: Available.

  2. 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 nameAvailability ZoneIPv4 subnet CIDR block
    quickcart-public-aus-east-1a10.0.1.0/24
    quickcart-app-aus-east-1a10.0.11.0/24

    Choose Create subnet.

    You should see

    Two subnets in the list. Right now both are private — neither has a route to the internet yet.

  3. Create the internet gateway and attach it

    In the AWS console: VPCInternet gatewaysCreate internet gateway

    FieldEnter
    Name tagquickcart-igw

    Choose Create internet gateway. Then choose Actions → Attach to VPC, pick quickcart-vpc, and choose Attach internet gateway.

    You should see

    State: Attached. On its own this makes nothing public — no subnet is using the gateway yet.

  4. Make the public subnet public

    In the AWS console: VPCRoute tablesCreate route table

    FieldEnter
    Namequickcart-rt-public
    VPCquickcart-vpc

    Choose Create route table. On its Routes tab, choose Edit routes, then Add route:

    DestinationTarget
    0.0.0.0/0Internet Gateway, then quickcart-igw

    Choose Save changes. Then open the Subnet associations tab, choose Edit subnet associations, tick quickcart-public-a, and choose Save associations.

    You should see

    The route table lists two routes: 10.0.0.0/16 → local and 0.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.

  5. Confirm the other subnet is still private

    In the AWS console: VPCSubnetsquickcart-app-aRoute table

    You should see

    Only one route: 10.0.0.0/16 → local. No way to the internet. The subnet is private because of what is missing.

  6. See the whole thing as a map

    In the AWS console: VPCYour VPCsquickcart-vpcResource map

    You should see

    A diagram: quickcart-public-a joined to quickcart-rt-public, which joins to quickcart-igw. quickcart-app-a joins to the VPC’s main route table, which goes nowhere outside.

  7. 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 delete in the box and choose Delete.

    You should see

    The 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

On one card
TermIn one line
VPCYour private network on AWS. Closed by default
SubnetA slice of the VPC, in one availability zone
Route tableThe rules for where a subnet’s traffic goes
Public subnetRoute table sends 0.0.0.0/0 to the internet gateway
Private subnetRoute table sends 0.0.0.0/0 to a NAT gateway — out only
Isolated subnetNo 0.0.0.0/0 route at all
local routeAlways there. Everything in the VPC can reach everything else
/16 and /2465,536 addresses and 256 addresses
Can’t reach something?Check the route table first

Finished the build and the quiz? Mark it done to fill in its stop on the route map.