Security Groups
Understand AWS security groups as stateful firewall rules for EC2, load balancers, databases, and other VPC resources.
Last reviewed: June 2026
🔍 What Is It?
A security group is a virtual firewall for AWS resources in a VPC.
It controls inbound and outbound traffic using allow rules. Security groups are stateful, so return traffic for allowed connections is automatically permitted.
🎯 Why Do We Need It?
Security groups enforce network least privilege.
They prevent direct exposure of application, database, and admin ports and help express which tiers are allowed to communicate.
Common developer mistakes:
- →Choosing defaults without checking security, cost, or failure behavior
- →Treating AWS services as isolated tools instead of part of an architecture
- →Skipping tags, alarms, IAM review, backups, and runbooks until production incidents happen
- →Building manually in the console and then struggling to reproduce environments
🏗️ What Happens in Real Projects?
A web app may use three security groups:
- →ALB allows inbound HTTPS from the internet
- →App allows inbound app port only from ALB security group
- →DB allows inbound database port only from app security group
This creates tiered network access without hardcoding IPs.
⚙️ How It Works
Rules specify protocol, port, and source or destination. Sources can be CIDR ranges or other security groups.
Because security groups are stateful, you usually define inbound access carefully and keep outbound access controlled based on enterprise policy.
💻 Example
Tiered security group model — Rules for a private application behind an ALB.
🤔 Common Confusions
❓ Are security groups stateless?
No. Security groups are stateful. Network ACLs are stateless.
❓ Can security groups deny traffic?
Security groups only contain allow rules. Lack of allow means traffic is denied.
❓ Should I use IPs or security group references?
Use security group references for tier-to-tier access where possible because instances can scale and change IPs.
🚨 Common Production Issues
**0.0.0.0/0 on admin ports** exposes SSH, RDP, or databases to the internet.
**Too many broad outbound rules** allow unnecessary data exfiltration paths.
**IP-based app rules** break when Auto Scaling replaces instances.
**Rule sprawl** makes firewall intent impossible to audit.
✅ Best Practices
Allow only required inbound ports
Reference security groups between tiers
Avoid public admin access; use SSM or VPN patterns
Review broad CIDR rules regularly
Name security groups by application and tier
Use infrastructure as code for rule ownership
🏛️ Architect's Note
Security groups are one of the clearest expressions of architecture. If the rules are broad and confusing, the system boundaries are probably broad and confusing too.
💬 Frequently Asked Questions
🎯 Key Takeaways
🔗 Related Topics
🎯 Practice this topic in interviews
↗ Where this topic fits
AWS Technology Guide
Return to the AWS learning hub.
Backend Engineer Career Path
A structured journey through Core Java, Spring Boot, production backend engineering, and interview preparation.
Python Developer Career Path
A practical route through Python fundamentals, automation, backend basics, testing, projects, interview preparation, and career growth.
Sources
Sources / References
Use these AWS references to verify the concept in official docs and continue into the most relevant SplashRide pages.
Official documentation
Related SplashRide pages
SplashRide AWS learning path
Browse the full AWS topic collection and learning order on SplashRide.
AWS Interview Prep
Practice AWS interview questions and scenario-based answers.
Backend Engineer Career Path
A structured journey through Core Java, Spring Boot, production backend engineering, and interview preparation.
Python Developer Career Path
A practical route through Python fundamentals, automation, backend basics, testing, projects, interview preparation, and career growth.
VPC
Understand Amazon VPC as the private network boundary for subnets, routing, security groups, NAT, load balancers, and workload isolation.
Subnets
Learn AWS subnets as AZ-scoped network segments for public, private, and isolated workload placement.