Back to writing

Networking and security: the two things between you and the cloud

A wise sage once said that only two things stand between you and the cloud: networking and security. The sage was right, and also a little dramatic. Here is what I wish I had known on day one, with fewer tears and more route tables.

The cloud is just someone else’s computer. Networking is how you reach it, and security is how you stop everyone else from reaching it too. Get those two right and the rest of AWS mostly behaves. Get them wrong and you will meet a timeout so patient it feels personal.

Your VPC does not live where you think it lives

Here is the mistake almost everyone makes, myself included: picturing a VPC sitting inside one Availability Zone. It does not. A VPC is an abstract thing. It belongs to a Region and quietly spans every Availability Zone (AZ) in it, like a company with offices in several buildings of the same city.

What does live in a single AZ is the subnet. A subnet is a slice of the VPC’s address range, placed in exactly one AZ. Think of the VPC as the company, the AZs as buildings and the subnets as floors: every floor is in one building, but nobody says the company is on the third floor. To spread an app across zones, you create a subnet in each AZ inside the same VPC. That is the whole trick behind “multi-AZ”.

Region: eu-west-1VPC 10.0.0.0/16belongs to the Region, spans every AZAvailability Zone apublic subnet10.0.1.0/24 · load balancerprivate subnet10.0.2.0/24 · app, databaseAvailability Zone bpublic subnet10.0.3.0/24 · load balancerprivate subnet10.0.4.0/24 · app, database
One VPC, one Region, many AZs. The VPC spans them; each subnet sits in exactly one.

A subnet is called public when its route table sends internet traffic to an internet gateway, and private when it does not. That is a property of the routing, not of the subnet’s personality.

Getting in and out: the front door, the turnstile and the side door

Traffic in and out of a VPC is where beginners lose a weekend, because there are several pieces and they all have to agree:

  • Internet gateway. The front door. It lets the VPC talk to the internet, and it belongs to the VPC rather than to an AZ, so it is not a single point of failure. A door alone is not enough: the subnet also needs a route to it, and the resource needs a public address.
  • Security groups and network ACLs. The bouncers. A security group sits on the resource and remembers conversations (it is stateful), so replies are allowed back automatically. A network ACL sits on the subnet and remembers nothing (stateless), so you allow both directions yourself. Most of the time the security group does the work.
  • NAT gateway. A one-way door for private subnets: your servers can call out to fetch updates, but strangers cannot call in. Unlike the VPC, it really does live in one AZ, and it charges by the hour and by the gigabyte, so think of it as a turnstile with a card reader.
  • Gateway endpoint. A private side door to S3 and DynamoDB. Traffic stays on the AWS network, nothing goes through the internet or the NAT gateway, and the endpoint itself is free.

That last one matters more than it looks. A private app that reads files from S3 through a NAT gateway pays for every gigabyte, just to reach a service that already lives inside AWS. A gateway endpoint takes the side door for free. Other AWS services have interface endpoints (built on PrivateLink), which also keep traffic private but are billed, so check the price before adding twenty of them.

Private subnetyour appNAT Gatewayout only, not freeInternet Gatewaythe front doorInternetthe wild westGateway endpointS3, DynamoDB: freeS3stays on AWSno internet, no NAT bill
Two ways out for a private app. The top one goes through the internet and costs money; the bottom one never leaves AWS.

Security: three places to lock the data

AWS and you share the work. AWS secures the cloud itself, meaning the buildings and the hardware; you secure what you put in it. That is the shared responsibility model, and “I thought AWS did that” is not a defence.

For data, think in three places: while it travels, while it sits on the server side, and while it is protected by you before it ever leaves.

WhereWhat it protectsWho does the work
In transitData moving between users and your app, or between servicesTLS (HTTPS). A free public certificate from AWS Certificate Manager covers load balancers and CloudFront
At rest, server sideData stored in S3, EBS, RDS and friendsAWS encrypts it for you, with keys from S3 or KMS
At rest, client sideData you encrypt before it leaves your appYou, with your own keys. AWS only sees scrambled bytes

TLS is the padlock in the browser: it stops people along the road from reading or changing your data. One catch: a load balancer often ends TLS, so behind it the traffic may be plain. That can be fine inside a private network, as long as it is a decision and not a surprise.

Server-side encryption is the easy win. S3 now encrypts new objects by default, so the real choice is whose key to use. Client-side encryption is for when even AWS should not see the plain data. It is more work and more responsibility: lose the key and the data is gone for everyone, including you.

Passwords: hash them, hide them, never commit them

There are two kinds of passwords, and two sets of rules.

Your users’ passwords are hashed, not encrypted. Encryption can be undone with the key, and a password should never need to be read back. Store a salted hash made with a slow algorithm such as bcrypt or Argon2, and compare hashes at login. If you can email someone their old password, something has gone wrong.

Your own secrets are not for code. Database passwords and API keys do not belong in the source, in a file that goes to git, or in a chat message sent “just this once”. Keep them in Secrets Manager or Parameter Store and let the app fetch them. For AWS itself, prefer IAM roles over long-lived access keys: a role hands out temporary credentials, while a key pushed to a public repository is found remarkably fast, usually by bots that never sleep. Add MFA for people, and give every role only the permissions it needs.

A tiny checklist

  • A VPC spans the Region. A subnet lives in one AZ. Say it out loud.
  • One public and one private subnet per AZ, and only the load balancer is public.
  • Use gateway endpoints for S3 and DynamoDB before paying a NAT gateway to do it.
  • HTTPS wherever people or services talk, and decide where TLS ends.
  • Let AWS encrypt at rest, and go client side only when you must.
  • Hash user passwords, keep secrets in a secrets store, and use roles instead of keys.
TakeawayNetworking decides who can reach what; security decides what they can do once they get there. Learn both early and the cloud turns boring, which is the highest praise infrastructure can get.

Working on something similar? Let's talk