Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Stateful behavior of security groups
📖 Scenario: You are setting up a simple cloud network for a small web application. You need to create a security group that allows incoming web traffic on port 80 and allows the server to respond to requests automatically without extra rules.
🎯 Goal: Create an AWS security group that allows inbound HTTP traffic on port 80 and demonstrates the stateful behavior by allowing outbound response traffic without explicit outbound rules.
📋 What You'll Learn
Create a security group named web-sg.
Add an inbound rule to allow TCP traffic on port 80 from anywhere (0.0.0.0/0).
Do not add any outbound rules explicitly.
Demonstrate the stateful behavior of the security group.
💡 Why This Matters
🌍 Real World
Security groups control network traffic to cloud resources. Understanding their stateful nature helps simplify firewall rules and secure applications.
💼 Career
Cloud engineers and DevOps professionals regularly configure security groups to protect applications while allowing necessary traffic.
Progress0 / 4 steps
1
Create the security group resource
Create an AWS security group resource named web_sg with the description Allow HTTP inbound and the VPC ID set to vpc-123abc.
AWS
Hint
Use the aws_security_group resource with the exact name web_sg.
2
Add inbound rule for HTTP traffic
Inside the aws_security_group resource web_sg, add an ingress block that allows TCP traffic on port 80 from 0.0.0.0/0.
AWS
Hint
Use an ingress block with from_port and to_port set to 80, protocol set to "tcp", and cidr_blocks set to ["0.0.0.0/0"].
3
Confirm no outbound rules are added
Ensure that the aws_security_group resource web_sg does not have any egress blocks defined, so it uses the default stateful outbound behavior.
AWS
Hint
Do not add any egress block to keep default outbound rules.
4
Add a tag to identify the security group
Add a tags block inside the aws_security_group resource web_sg with the tag Environment set to Development.
AWS
Hint
Use a tags block with the key Environment and value Development.
Practice
(1/5)
1. What does it mean when we say AWS security groups are stateful?
easy
A. Return traffic is automatically allowed, even if no outbound rule exists
B. You must create separate rules for inbound and outbound traffic
C. Security groups remember user login sessions
D. They block all traffic by default without exceptions
Solution
Step 1: Understand stateful behavior in security groups
Stateful means the security group tracks connections and allows return traffic automatically.
Step 2: Apply this to inbound and outbound rules
If inbound traffic is allowed, the response outbound traffic is automatically allowed without explicit outbound rules.
Final Answer:
Return traffic is automatically allowed, even if no outbound rule exists -> Option A
Thinking outbound rules must explicitly allow return traffic
Confusing inbound and outbound directions
Assuming NAT gateway is needed for return traffic
4. You created a security group with only an outbound rule allowing all traffic, but no inbound rules. You cannot connect to your instance via SSH. What is the likely problem?
medium
A. Inbound SSH traffic is blocked because no inbound rule allows port 22
B. Outbound rules block SSH response traffic
C. Security groups require both inbound and outbound rules for SSH
D. The instance must have a public IP to allow SSH
Solution
Step 1: Analyze the security group rules
Only outbound rules exist; no inbound rules allow SSH (port 22).
Step 2: Understand inbound rules control incoming connections
Without inbound port 22 allowed, SSH connection attempts are blocked.
Final Answer:
Inbound SSH traffic is blocked because no inbound rule allows port 22 -> Option A
Quick Check:
No inbound port 22 = no SSH access [OK]
Hint: Inbound rules must allow SSH for connection [OK]
Common Mistakes:
Assuming outbound rules control incoming SSH
Thinking both inbound and outbound rules are mandatory for SSH
Ignoring instance public IP requirement
5. You want to allow inbound HTTP traffic from anywhere and ensure your instance can respond properly. Which security group configuration achieves this with minimal rules?
hard
A. Allow inbound TCP port 80 and outbound TCP port 80 from 0.0.0.0/0
B. Allow inbound TCP port 80 from 0.0.0.0/0 and outbound all traffic
C. Allow inbound TCP port 80 from 0.0.0.0/0 only
D. Allow inbound all traffic and outbound all traffic
Solution
Step 1: Recall stateful behavior of security groups