VPC - An analogy about shared resources
Public subnets and Internet Gateway
Load balancing - one front door, many clerks
<aside> 🚧
This page is currently under construction. Please check back later.
</aside>
<aside> 🧱
The full picture — recap
You have now built every layer of the week's architecture yourself, one section at a time. This page puts the three sections back together into a single diagram, walks a real request through it end to end, and gives you a checklist to tear it all down before it costs you money.
Nothing new is introduced here. If something below feels unfamiliar, that is a signal to go back to the section that built it.
</aside>
Read it once more, now that every box means something to you:
| Where | What lives there | Route table | Reachable from |
|---|---|---|---|
| Public subnet — AZ A | |||
10.0.1.0/24 |
hyf-web, hyf-bastion, Internet Gateway, NAT Gateway |
0.0.0.0/0 → IGW |
the internet |
| Private subnet — AZ A | |||
10.0.2.0/24 |
hyf-app |
0.0.0.0/0 → NAT |
hyf-web (and hyf-bastion, port 22 only) |
| Private subnet — AZ B | |||
10.0.3.0/24 |
hyf-db • S3 gateway endpoint on its route table |
local, plus a prefix-list route to S3 |
hyf-app (and hyf-bastion, port 22 only) |
Three subnets, three route tables, four security groups, and one rule that ties the whole thing together: each tier accepts traffic only from the tier directly above it — with a single bastion as the one way in for a human being.
hyf-week4-vpc, which translates the public IP to hyf-web's private IP 10.0.1.x.hyf-web-sg is checked: TCP 80 from 0.0.0.0/0 is allowed. The packet is delivered.10.0.2.x:3000. The route table finds this inside 10.0.0.0/16 → the local route keeps it inside the VPC.hyf-app-sg is checked: TCP 3000 from hyf-web-sg is allowed, and the caller is wearing that badge. Delivered.10.0.3.x:5432. Same local route — this hop crosses from AZ A to AZ B and needs no gateway to do it.hyf-db-sg is checked: TCP 5432 from hyf-app-sg is allowed. Delivered.<aside> 💭
Count the ways an attacker who owns hyf-web is still stuck. They cannot reach hyf-db — no security group rule matches them. They cannot reach the internet from hyf-db even if they got there — the only route out of that subnet leads to S3. And nothing outside can address hyf-app or hyf-db at all — no public IPs. That layering is the point of the whole week.
</aside>
hyf-app runs apt updatehyf-app sends a packet to a public repository address. Not inside 10.0.0.0/16, so the local route does not match.hyf-week4-private-rt-a matches 0.0.0.0/0 → NAT Gateway.hyf-app.hyf-dbhyf-bastion's public IP. It sits in the public subnet, so the Internet Gateway delivers the packet, and hyf-bastion-sg allows TCP 22 from your address and no other.10.0.3.x. That address is inside 10.0.0.0/16, so the local route carries it — across the AZ boundary, with no gateway involved.hyf-db-sg allows TCP 22 from hyf-bastion-sg, and the caller is wearing that badge. You have a shell on a machine with no public IP and no route to the internet.ssh -J, your private key never touches the bastion — it only forwards the encrypted tunnel.hyf-db pushes a backup to S3hyf-db sends a packet to s3.eu-central-1.amazonaws.com, which resolves to a public S3 address — a gateway endpoint changes routing, not DNS.hyf-week4-private-rt-b has no 0.0.0.0/0 route, but it does have one whose destination is the S3 prefix list. That route matches.curl https://example.com — matches no route at all, and times out. One door, one service.| Decision | Reason | What breaks without it |
|---|---|---|
| Web server in a public subnet | It is the only tier users must reach directly | Nobody can load your site |
| App server in a private subnet, same AZ | Business logic should not be internet-addressable; same AZ avoids cross-AZ hops and charges for NAT traffic | Your API is exposed to the whole internet |
| NAT Gateway in the public subnet | It needs its own route to the IGW to work | Nothing outbound works; the NAT is useless |
| Database in a second AZ | Survives the loss of a whole data centre | One AZ failure takes your data offline |
Database subnet with no 0.0.0.0/0 route |
Data has no business calling the internet | A compromised database can exfiltrate data outbound |
| An S3 gateway endpoint instead of a NAT route for the DB subnet | Grants exactly one AWS service, not the whole internet — and a gateway endpoint is free | You either give up backups, or reopen the internet to your data |
| A single bastion as the only way in | One machine to guard, one rule in the VPC that mentions the internet, and it works even for a subnet with no route out | Either every tier needs its own SSH rule, or private instances cannot be administered at all |
| Security groups referencing other security groups | Rules survive instance replacement and IP changes | Hardcoded IPs break on every redeploy |
Almost every VPC problem is one of five things. Work down the list in order — it is roughly the order of how often each is the culprit.
<aside> 💡
When you are properly stuck, use VPC Reachability Analyzer (VPC console → Reachability Analyzer). You give it a source and a destination, and it tells you exactly which route table, security group or NACL is blocking the path. It is the fastest way to stop guessing.
</aside>
Answer these before moving on. Try to answer out loud first, then open the toggle.
hyf-app reaches hyf-db in a different Availability Zone. Which gateway makes that possible?hyf-web can ping hyf-app but a connection to hyf-db on 5432 times out. Why?hyf-db?0.0.0.0/0 route, yet aws s3 cp works. What did you add, and what did it change?<aside> 💰
</aside>
hyf-bastion, hyf-web, hyf-app, hyf-db)hyf-week4-s3-endpoint) — free to keep, but it holds a route in private-rt-bpublic-rt, private-rt-a, private-rt-b)hyf-bastion-sg, hyf-web-sg, hyf-app-sg, hyf-db-sg)hyf-week4-vpchyf-db-role IAM role and your S3 bucket cost nothing to keep — delete them too if you like a tidy account<aside> 💡
</aside>
This architecture has one obvious weakness left: a single web server, in a single Availability Zone. If it dies, or if traffic doubles, you have no answer.
That is exactly what Load Balancing and Scaling — the second topic of this week — solves, and it is why the diagram was drawn with an empty slot in front of the web tier. The pieces you will add there (an Application Load Balancer spanning both AZs, and an Auto Scaling group behind it) all plug into the subnets and security groups you just built.