23.7 VPC Flow Logs: Capturing Accept and Reject Traffic for Analysis

Right, let’s talk about VPC Flow Logs. This is where we stop guessing why that darn instance can’t talk to the database and start knowing. Think of Security Groups and NACLs as your bouncers—they decide who gets in and who gets tossed out. Flow Logs are the meticulous club managers who keep a perfect record of every single decision those bouncers made, plus all the randos who showed up without an invite. It’s your first, last, and best tool for untangling the rat’s nest of network connectivity issues in your VPC.

23.6 Security Groups vs NACLs: When to Use Each

Right, let’s settle this. You’ve got these two tools in your AWS toolbox for locking down your VPC: Security Groups and Network ACLs. It’s tempting to think they’re just two ways to do the same thing, but that’s a fast track to a security headache or a 3 AM outage call. One is a bouncer with a guest list; the other is a mindless, automated gate. Knowing which is which is non-negotiable.

23.5 NACL Rule Evaluation: Numbered Rules and the Implicit Deny

Alright, let’s get into the weeds on NACLs. If Security Groups are your bouncer, checking IDs at the door of your instance, then NACLs are the building’s security gate. They’re stateless, they work at the subnet level, and they have a set of numbered rules that they evaluate in order. This is where things get both powerful and, frankly, a bit silly if you’re not careful. The single most important concept to burn into your brain is this: NACLs evaluate their numbered rules in ascending order, from the lowest number to the highest, until they find a match. The first rule that matches the traffic type is the one that gets applied, full stop. It doesn’t keep looking. This is why you can’t just slap rules in there willy-nilly; order is absolutely everything.

23.4 NACLs: Stateless Subnet-Level Firewall

Right, let’s talk about NACLs. If Security Groups are your application’s loyal, detail-obsessed bouncers (checking every single ID at the door), then NACLs are the distracted, easily overwhelmed security guard at the perimeter gate who has a list of rules but keeps forgetting who just walked in or out. The core, and frankly most annoying, thing to remember about NACLs is that they are stateless. This isn’t a philosophical stance; it’s a technical reality that will bite you if you forget it. Let me explain: a Security Group is stateful. You allow SSH inbound, and the return traffic for that connection is automatically allowed back out, no questions asked. It remembers. NACLs have the memory of a goldfish. If an EC2 instance inside your subnet sends a request out (e.g., to download a software update from the internet), the outbound request might be allowed by the outbound rules. But when the response traffic comes back into the subnet, the NACL has completely forgotten about the original request. That return traffic must be explicitly permitted by an inbound rule. This is the single biggest “gotcha” and the source of most head-scratching “why can’t my instance get to the internet?” problems.

23.3 Security Group References: Allowing Traffic from Another SG

Right, let’s talk about one of AWS’s more elegant features that they somehow managed to make feel clunky: allowing one security group to talk to another. It’s the networking equivalent of saying, “My friend here is cool, let him in,” instead of having to check his ID every single time. We call this a security group reference. The core idea is beautifully simple. Instead of specifying a CIDR block (like 10.0.0.0/16) as the source in your security group’s inbound rule, you specify another security group’s ID (like sg-0a1b2c3d4e5f67890). This creates a dynamic, logical rule: “Allow traffic from any network interface that is currently attached to the source security group.”

23.2 Inbound and Outbound Rules: Protocol, Port Range, Source/Destination

Alright, let’s get into the weeds of the actual rules. This is where the rubber meets the road, and where most people, frankly, screw it up. Security Groups and NACLs don’t just magically allow traffic; you have to explicitly tell them what to permit or deny using a combination of three key elements: protocol, port range, and source/destination. Think of it as a very picky bouncer at an exclusive club. You have to tell him exactly who gets in (source), what kind of party they’re going to (port), and how they’re allowed to communicate (protocol).

23.1 Security Groups: Stateful Firewall Rules at the ENI Level

Alright, let’s talk about the first line of defense for your EC2 instances: Security Groups. Forget the dry, academic definitions. Think of a Security Group as a bouncer for a single, specific VIP party—your Elastic Network Interface (ENI). This bouncer isn’t just any bouncer; he’s got a photographic memory. He remembers who you came in with, so he’ll let you back out without checking your invite again. This “memory” is what we call statefulness, and it’s the single most important thing to understand.

— joke —

...