πŸ” What are Security Groups?

AΒ Security Group in AWS acts like a virtual firewall that controls inbound and outbound traffic for your EC2 instances and other supported services (like RDS, Lambda with VPC, etc.).

βœ… Security Groups define who can access your instance and on which ports.


🧩 Key Features

Feature Description
Stateful If you allow inbound traffic, response is auto-allowed
Attached to Instances Applied at the instance level, not subnet
VPC-bound Security Groups are scoped to a single VPC
Allow Rules Only You can’t explicitly deny traffic β€” only allow

πŸ” Traffic Rules

Rule Type What It Does Example
Inbound Defines who can connect to your instance Allow SSH from your IP
Outbound Defines where your instance can connect Allow all traffic to internet

πŸ› οΈ Common Use Cases

Use Case Inbound Rule
SSH Access Port 22 from your-IP/32
HTTP Web Server Port 80 from 0.0.0.0/0 (anywhere)
HTTPS (SSL) Web Server Port 443 from 0.0.0.0/0
MySQL DB Access Port 3306 from specific private IP range

βš™οΈ How to Configure (AWS Console)

  1. Go to VPC β†’ Security Groups
  2. Create or edit a security group
  3. Add inbound rules (type, port, source)
  4. Add outbound rules (default: all allowed)
  5. Attach the security group to EC2 instance(s)

πŸ”„ Stateful Behavior Example

If you allow:

Inbound: HTTP (80) from 0.0.0.0/0

Then AWS automatically allows:

Outbound: HTTP response back to sender

❗ You don’t need to manually add an outbound rule for the response.


πŸ“¦ Security Groups vs NACLs

Feature Security Group Network ACL
Scope Instance-level Subnet-level
Rules Allow only Allow and Deny
Stateful? βœ… Yes ❌ No
Use Case App-level access control Broad subnet-based filtering

βœ… Summary

Attribute Value
Type Virtual firewall for EC2 and other services
Default Behavior Deny all inbound, allow all outbound
Rule Direction Inbound and outbound (no deny rule support)
Security Level Instance-specific
Back to blog

Leave a comment