
A private network, one front door
Course 3 · Today your app leaves the open internet
Today
| When | What | Where |
|---|---|---|
| 0:00 | Recap: what's wrong with your M1 deploy | Lecture |
| 0:10 | VPC, CIDR, subnets, routes, IGW, NAT | Lecture |
| 0:45 | Security groups vs NACLs, the chain, endpoints, connecting networks | Lecture |
| 1:10 | Load balancers, what Floci emulates vs what AWS routes | Lecture |
| 1:35 | M2: VPC, subnets, doors | Project |
| 2:00 | M2: SG chain, new ALB, app and DB move in | Project |
| 3:00 | Intruder test, break drill | Project |
| 3:25 | Tear down v1, check M2, commit | Project |

Recap
Last session, everything was public
The database, the API on port 8080, SSH. Only a password stood between the internet and our data.

A VPC is your own gated neighborhood
A private network in one Region, across all its AZs. Nothing gets in unless you open a way in.

Puff's range. The first 16 bits are fixed, the last 16 are yours: 65,536 addresses.
Counting addresses
| Size | Addresses | Where you meet it |
|---|---|---|
/16 | 65,536 | Puff's VPC, the largest AWS allows |
/20 | 4,096 | Each of Puff's four subnets |
/24 | 256, 251 usable | A classic subnet, AWS keeps 5 |
/28 | 16, 11 usable | The smallest VPC |
Private IPs cost nothing, so Puff's /20 subnets are far bigger than it needs.
Ranges that will collide one day
Home routers192.168.0.0/24or192.168.1.0/24
DockerThe default bridge on172.17.0.0/16
CompaniesA lot of corporate networks somewhere in10.0.0.0/8
AWSRefuses to connect overlapping VPCs. Fixing it later means rebuilding the network

At Alan, networks that may need to talk get non-overlapping ranges, decided before the network exists. Changing one later takes weeks.

There's no "public" checkbox
A subnet is public when its route table sends 0.0.0.0/0 to an Internet Gateway. Private when it doesn't.
Two route tables, one difference
| Destination | Public | Private |
|---|---|---|
10.0.0.0/16 | local | local |
0.0.0.0/0 | igw-... Internet Gateway | nat-... NAT gateway |
S3 prefix list pl-... | vpce-... endpoint | vpce-... endpoint |
Don't trust a subnet's name. Open its route table and look where 0.0.0.0/0 goes.
The two doors

Internet Gateway
Two ways, either side can start. One per VPC, free

NAT gateway
A one-way exit in a public subnet. Private servers go out, nothing comes in
The private API still needs Docker, python:3.12-slim and OS updates. A way out that isn't a way in.
Three trips through Puff's network
A visitorInternet Gateway, then the ALB, then the API, then the database
A downloadAPI, then NAT gateway, then Internet Gateway, then Docker Hub, and the reply comes back
A strangerStopped. The API has no public IP, and its subnet has no way in

A NAT gateway doing nothing, in us-east-1. Plus $0.045 per GB. It keeps charging while you sleep.

Skip the NAT, give the API a public IP and a strict security group. Less safe?
What happens the day someone edits that rule by mistake?
Two firewalls
| Security group | Network ACL | |
|---|---|---|
| Applies to | One server's network card | A whole subnet |
| Memory | Remembers, replies go out by themselves | None, replies need their own rule |
| Rules | Allow only | Allow and deny |
| Reads rules | All at once, any match lets you in | In number order, first match wins |
| When you use it | Every day | Rarely, to block one IP range |
Security groups do 95% of the work. Leave NACLs at their default.
Puff's chain, read it from the bottom
| Security group | Inbound | Source |
|---|---|---|
alb-sg | TCP 80 | 0.0.0.0/0 |
app-sg | TCP 80 | alb-sg (on Floci: 172.17.0.0/16) |
db-sg | TCP 5432 | app-sg |
The best rules don't mention IPs. A stranger can only reach port 80 on the ALB.

Your private app reaches the internet but not your database, same VPC. Where do you look?
Three places, in order.
In a data center
| In AWS | In a data center | |
|---|---|---|
| A slice of network | Subnet | VLAN on physical switches |
| The firewall | Security group | A firewall appliance |
| The public part | Public subnet | The DMZ |
| The front door | Load balancer | A hardware box, F5 is the classic |
| Two sites talk | Peering, VPN | A leased line or MPLS |
| Changing a rule | An API call | A ticket to the network team |
Same ideas turned into software: SDN. The network becomes an API, and you just built one.

500 GB of backups to S3 through the NAT, every month. Add the S3 gateway endpoint and that line drops to zero.
A private path to AWS

Gateway endpoint
S3 and DynamoDB only. A line in the route table, free

Interface endpoint
Most other services. A network card in your subnet, billed per hour and per GB
Four ways to link networks, small to big
VPC peeringTwo VPCs, free to set up. It doesn't chain: A to B, B to C, A still can't reach C
Transit GatewayA hub every VPC and VPN connects to once, like a roundabout
Site-to-Site VPNAn encrypted tunnel over the internet to an office. Up in an hour
Direct ConnectA private physical cable from a data center into AWS. Takes weeks
Which one, when
| Situation | Use | Why |
|---|---|---|
| Two or three VPCs need to talk | VPC peering | Simple and free |
| Ten VPCs across accounts, plus an office | Transit Gateway | One connection per network, one place for routing |
| Office needs AWS this week | Site-to-Site VPN | Fast, encrypted, cheap |
| Terabytes a day, steady speed | Direct Connect, VPN as backup | Predictable speed, cheaper at volume |
None of them works with overlapping ranges. The IP plan keeps all four open.

Peering connections for ten VPCs that all talk. A Transit Gateway does it with ten attachments.

An analytics VPC needs your database, and an office needs both. What do you pick?
And which choice from today could make it impossible?
The load balancer, the only public door
ListenersThe port it accepts, like HTTP 80
Target groupsThe instances it forwards to, with a health check
RulesThey connect the two
ALB or NLB
| ALB | NLB | |
|---|---|---|
| Understands | Web traffic, HTTP and HTTPS, layer 7 | Raw connections, TCP, UDP, TLS, layer 4 |
| Routes by | Path, host, header, query string | Port only |
| Address | A DNS name, IPs behind it change | One fixed IP per AZ |
| Pick it for | Web apps and APIs, your app | Non-web protocols, fixed IPs to allowlist |
Anything that speaks HTTP, start with an ALB.

Hands-on
Project M2: a private network with one front door
✅ ./checks/check.sh M2 all PASS, ./checks/intruder.sh says the app is BLOCKED

The ALB lives in two AZs, your app in one container. What's the weak point?
Everything from today is on the course page.
