Security groups: stateful, instance-level firewalls
coreintermediateA security group is a stateful firewall attached to a resource (an instance, a load balancer, an RDS database) — it can only allow traffic, never explicitly deny, and once inbound traffic is allowed, the matching return traffic is automatically allowed back out.
Think of it as
A guest list at a private event: the list only says who gets in (allow-only, no explicit deny needed for everyone else), and once someone is let in, they can freely leave without being checked again at the door.
What we're doing: See a security group referencing another security group as its source, instead of a hardcoded IP range.
- 3
- The source is another security group (sg-0alb456, the load balancer's), not a CIDR block.
- 4
- Any instance later added to sg-0alb456 automatically gets this access — nothing on the app side needs to change.
Why this works: Referencing a security group instead of a fixed IP range means the rule stays correct automatically as instances behind the load balancer scale up, down, or get replaced — a hardcoded IP range would need updating every time.
Trying to add an explicit "deny" rule to a security group
Wrong
Better
What you see: The console or CLI offers no way to add a "deny" entry — only "allow" — and confusion follows about how to block a specific range.
Why: A security group's rule set is a list of allows, evaluated as a whole — anything not explicitly allowed is implicitly denied, but there is no mechanism to explicitly deny something that would otherwise match an allow rule. That capability exists one layer up, at the network ACL.
- Inbound rule added
- Allow TCP 443 from sg-alb (the load balancer's security group)
- A request from that source on port 443 is let through
- No outbound rule needed for the reply
- The response to that same connection is automatically allowed out
- No matching outbound rule had to be added by hand
Remember: Security groups are stateful and allow-only, attached to the resource itself — return traffic for an allowed connection is automatic, and there is no explicit deny.
See also: network acls as stateless controls · layered controls design

