Security Group (SG)
Attaches directly to EC2 instances, Application Load Balancers, RDS databases, Lambda VPC interfaces, and VPC endpoints. Evaluates all rules before traffic reaches the operating system. Because it is stateful, return traffic is automatically allowed regardless of outbound rules. Supports least-privilege security group ID reference chaining.
AWS Container Placement
VPC
Summary
Stateful virtual firewall controlling inbound and outbound traffic at the Elastic Network Interface (ENI) level.
When to Use (SAA-C03)
Use SG-to-SG chaining (e.g., RDS SG allows port 5432 from App SG ID) instead of broad VPC CIDRs; remember SGs cannot have explicit Deny rules.
Allowed Ingress Connections & Ports
| Source Service | Protocol | Port | Architectural Rationale |
|---|---|---|---|
| WEBCLIENT | HTTP, HTTPS | 80, 443 | Public web browsers and API consumers accessing entry points |
| ALB | HTTP, HTTPS, TCP | 80, 443, 8080, 3000 | Load balancers forwarding traffic to backend compute targets |
| EC2 | TCP, UDP, ICMP | Any port (e.g. 5432, 6379, 3306) | Chained instance-to-instance or tier-to-tier microsegmentation |
| LAMBDA | TCP | Any port | VPC-attached Lambda functions invoking internal databases or services |
Allowed Egress Targets & Ports
| Target Service | Protocol | Port | Data Flow Rationale |
|---|---|---|---|
| EC2 | TCP, UDP | Any port | Internal application routing between microservice tiers |
| RDS | TCP | 5432 (Postgres), 3306 (MySQL), 1433 (MSSQL) | Direct transactional database queries |
| ELASTICACHE | TCP | 6379 (Redis), 11211 (Memcached) | Low-latency in-memory cache clustering |
| INTERFACE-ENDPOINT | HTTPS | 443 | PrivateLink connections to AWS APIs (SSM, KMS, SQS, S3) |
Key Configuration Parameters & AWS Best Practices
| Parameter | Format / Example | Purpose & Rationale |
|---|---|---|
| Security Group Name (name) (Required) | sg-app-backend-prod | Unique name identifier for the Security Group within the AWS account and VPC. Why: AWS requires a name for every security group resource created in EC2-VPC. |
| VPC ID (vpcId) (Required) | vpc-0a1b2c3d4e5f67890 | Identifies the VPC boundary that contains this Security Group. Why: Security Groups are strictly bound to a single VPC; rules cannot reference SGs across un-peered VPCs. |
| Inbound Rules (inboundRules) (Required) | TCP 443 from 0.0.0.0/0 or sg-alb | Whitelist specifying permitted ingress traffic protocols, port ranges, and authorized sources (CIDRs, Prefix Lists, or other SG IDs). Why: Default posture of a Security Group is to block ALL inbound traffic until explicitly permitted. |
| Outbound Rules (outboundRules) (Required) | All traffic to 0.0.0.0/0 (Default) or TCP 5432 to sg-db | Whitelist specifying permitted egress traffic protocols, ports, and destinations. Why: Controls outbound traffic initiated by the instance. AWS creates a default allow-all outbound rule, but hardened workloads lock it down. |
| Description (description) | Controls ingress to backend API containers from public ALB | Human-readable documentation describing the purpose and security posture of this group. Why: Assists security auditing, Well-Architected reviews, and compliance tracking. |
| Revoke Rules on Delete (revoke_rules_on_delete) | true | Instructs Terraform to revoke all attached security group rules before deleting the group. Why: Prevents DependencyViolation errors during terraform destroy cycles when circular SG references exist. |
| Tags (tags) | Environment: Production, ManagedBy: Terraform | Metadata tags for cost allocation, environment scoping, and infrastructure automation. Why: Enables enterprise resource management and automated compliance scans. |
Practice Labs Using Security Group
Locked-Out Security Group Ingress
Add an inbound rule allowing TCP port 80 from 0.0.0.0/0 to the web instance Security Group.…
CLF-03Public Database Exposure Vulnerability
Move or configure RDS to be in a private subnet, disable public accessibility, and restrict ingress exclusivel…
SAA-05SaaS Multi-Tenant DB: Least-Privilege Security Group Chaining
Replace CIDR 10.0.0.0/16 with the Application Security Group ID (sg-app) as the authorized source on port 5432…
SAA-08Multi-Tier Highly Available Web Architecture: Dual-AZ ALB, ASG Fleet & Multi-AZ RDS
Re-architect for multi-AZ high availability: map the public ALB across dual AZs (us-east-1a and us-east-1b), d…
SAA-12Publish Private Compute: Secure Route 53 CNAME & Dual-AZ ALB Reverse Proxy
Expose the private EC2 compute service via an Internet-Facing ALB spanning two public AZs, configure Target Gr…
SAA-13FinTech SaaS Link: PrivateLink Interface Endpoint Security Group Block
Add an inbound rule to sg-vpce allowing TCP port 443 from sg-app.…
Frequently Asked Questions
Where does Security Group live inside an AWS VPC architecture?
Valid container placement: VPC. Attaches directly to EC2 instances, Application Load Balancers, RDS databases, Lambda VPC interfaces, and VPC endpoints. Evaluates all rules before traffic reaches the operating system. Because it is stateful, return traffic is automatically allowed regardless of outbound rules. Supports least-privilege security group ID reference chaining.
When should I use Security Group on the AWS SAA-C03 exam?
Use SG-to-SG chaining (e.g., RDS SG allows port 5432 from App SG ID) instead of broad VPC CIDRs; remember SGs cannot have explicit Deny rules.
Can I simulate Security Group packet routing without an AWS account?
Yes. CloudTracer simulates Security Group along with 53 AWS services directly in your browser and exports production Terraform HCL.