Easy Steps to Create and Configure AWS Security Groups

Step-by-Step Guide: How to Create and Configure Security Groups in AWS
Security Groups in AWS act as virtual firewalls for your instances, controlling inbound and outbound traffic. They are essential for securing your cloud infrastructure. In this guide, we'll walk through creating and configuring Security Groups in AWS.
Prerequisites
An AWS account with appropriate IAM permissions.
Basic understanding of networking concepts (IP addresses, ports, protocols).
Step 1: Log in to AWS Management Console
Go to the AWS Management Console.
Sign in with your credentials.
Navigate to the EC2 Dashboard.
Step 2: Create a Security Group
In the left navigation pane, click "Security Groups" under "Network & Security."
Click the "Create security group" button.
Basic Details
Security group name: Give a descriptive name (e.g.,
WebServer-SG
).Description: Add a brief explanation (e.g., "Allow HTTP/HTTPS and SSH access").
VPC: Select the Virtual Private Cloud (VPC) where your instances reside.
Step 3: Configure Inbound Rules
Inbound rules control incoming traffic to your instances.
Under "Inbound rules," click "Add rule."
Choose common rules or customize:
Type: Select a protocol (e.g., HTTP, HTTPS, SSH, RDP, or Custom TCP).
Port range: Define the port (e.g.,
80
for HTTP,22
for SSH).Source: Specify allowed IPs:
For public access:
0.0.0.0/0
(any IP) – Use with caution!For restricted access: Enter a specific IP or another Security Group.
Example Inbound Rules:
Type | Protocol | Port Range | Source |
HTTP | TCP | 80 | 0.0.0.0/0 |
HTTPS | TCP | 443 | 0.0.0.0/0 |
SSH | TCP | 22 | Your-IP/32 |
Step 4: Configure Outbound Rules
Outbound rules control traffic leaving your instances.
Under "Outbound rules," click "Add rule."
By default, AWS allows all outbound traffic (
0.0.0.0/0
).For stricter security, limit outbound traffic to necessary ports.
Example Outbound Rules:
Type | Protocol | Port Range | Destination |
HTTPS | TCP | 443 | 0.0.0.0/0 |
Custom TCP | TCP | 3306 | DB-SG (if using RDS) |
Step 5: Save the Security Group
Review your rules.
Click "Create security group."
Step 6: Assign the Security Group to an Instance
Go to EC2 Dashboard > Instances.
Select an instance and click "Actions" > "Security" > "Change security groups."
Select your newly created Security Group and click "Assign security groups."
Step 7: Test Connectivity
For SSH:
ssh -i your-key.pem ec2-user@<Public-IP>
For HTTP: Open a browser and enter
http://<Public-IP>
If access is denied, recheck Security Group rules and instance firewall settings.
Best Practices for Security Groups
✅ Least Privilege Principle: Only allow necessary ports/IPs.
✅ Use Descriptive Names: Helps in identifying purpose (e.g., Web-SG
, DB-SG
).
✅ Reference Security Groups: Instead of IPs, reference other Security Groups for internal traffic.
✅ Regular Audits: Review rules periodically to remove unused access.
✅ Avoid Open Rules: Never use 0.0.0.0/0
unless absolutely required.
Conclusion
Security Groups are a fundamental part of AWS security. By following this guide, you can create and configure them effectively to protect your cloud resources. Always follow security best practices to minimize risks.
hashnode :-https://hashnode.com/post/cmcuuve48000502lbdvwjbvqq
Subscribe to my newsletter
Read articles from Bhashkar Kushwaha directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
