How Security Groups Filter Traffic
Understand the stateful firewall attached to each resource.
How Security Groups Filter Traffic is a free AWS Security Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AWS Security Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
The Resource Firewall
A security group (SG) is a virtual firewall that attaches directly to an elastic network interface (ENI) on a resource such as an EC2 instance, an RDS database, or a load balancer. It controls inbound and outbound traffic at the resource level rather than at the network boundary, so two instances in the same subnet can have very different rules.
Allow-Only Rules
Security groups contain allow rules only. There is no way to write an explicit deny. Any traffic that does not match an allow rule is simply dropped. This means you build access by adding the permits you want, and the implicit default is to block everything else.
Default Behavior
A brand-new security group denies all inbound traffic and allows all outbound traffic. You open inbound access deliberately, port by port, while egress stays wide open unless you tighten it. Exam scenarios often hinge on remembering that outbound is permissive by default.
Anatomy of a Rule
Each rule defines a protocol (TCP, UDP, ICMP), a port range, and a source (for inbound) or destination (for outbound). The source can be a CIDR block such as 10.0.0.0/16 or another security group ID, letting you reference groups instead of fixed IPs.
aws ec2 authorize-security-group-ingress \
--group-id sg-0abc123 \
--protocol tcp --port 443 \
--cidr 0.0.0.0/0Referencing Other Groups
Setting the source to another security group ID creates dynamic, identity-based access. For example, a database SG can allow port 5432 only from the application tier SG. As app servers scale up and down, no IP edits are needed because membership in the referenced group governs access.
Stateful Tracking
Security groups are stateful. When you allow an inbound request, the response is automatically allowed back out regardless of outbound rules, and vice versa. The connection is tracked, so you never write a matching return rule. This is the single biggest behavioral difference from network ACLs.
Multiple Groups per Resource
A single ENI can have several security groups attached at once. Their rules are combined as a union: if any attached group allows the traffic, it is permitted. There is no rule ordering or priority, so you cannot use one group to override another with a deny.
Least-Privilege Design
Apply least privilege by opening only the exact ports each tier needs. A web tier might allow 443 from the internet; an app tier allows 8080 only from the web SG; a data tier allows 3306 only from the app SG. This tiered chaining limits lateral movement after a breach.
Common Mistakes
The most dangerous misconfiguration is allowing 0.0.0.0/0 on port 22 or 3389, exposing SSH or RDP to the whole internet. GuardDuty and Security Hub flag these. Prefer no inbound admin ports at all, using Session Manager instead, which the SSM course covers.
Logging Gap
Security groups themselves do not log allowed or denied packets. To see what traffic actually flowed, you rely on VPC Flow Logs, which record the accept or reject decision per connection. Pair SG design with Flow Logs to verify your rules behave as intended.
Where They Fit
Security groups are your first and most granular line of network defense inside a VPC, working at the instance level. They complement subnet-wide network ACLs and application-layer tools like WAF. Mastering their stateful, allow-only, union behavior is essential for the SCS-C02 exam.
Quick Check
Test your grasp of security group behavior.
Recap
Security groups are stateful, allow-only virtual firewalls attached at the resource ENI. New groups deny all inbound, allow all outbound. Rules specify protocol, port, and a source that can be a CIDR or another group ID. Multiple groups combine as a union with no deny or ordering. Avoid open admin ports, and use Flow Logs to observe traffic since SGs do not log.
Frequently asked questions
Is the “How Security Groups Filter Traffic” lesson free?
Yes — the full text of “How Security Groups Filter Traffic” is free to read here on the web, and the AWS Security Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AWS Security Academy course, upgrade to CoddyKit PRO.
What will I learn in “How Security Groups Filter Traffic”?
Understand the stateful firewall attached to each resource. You practise AWS Security Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start AWS Security Academy?
No prior experience is required. AWS Security Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “How Security Groups Filter Traffic” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this AWS Security Academy lesson?
Yes. Every AWS Security Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- How Security Groups Filter Traffic
- How Network ACLs Filter Subnets
- Stateful versus Stateless Behavior
- Layering Both for Defense in Depth