Security Groups in AWS...!

Β·

4 min read

Security Groups in AWS...!

Day 2: Configuring Security Groups in AWS – A Step-by-Step Guide

Hello Dosto...! πŸ‘‹

Welcome to Day 2 of my 90 Days of DevOps 2025 journey! Today, I explored AWS Security Groups, a crucial aspect of cloud networking. In this blog, I will take you through a step-by-step guide on how to create and configure Security Groups in AWS to control inbound and outbound traffic for your EC2 instances.

Let’s dive in! πŸš€


What Are Security Groups?

Security Groups act as virtual firewalls for AWS instances, defining what kind of traffic is allowed in and out. They play a key role in network security, ensuring only authorized access to cloud resources.

Key Features of Security Groups

βœ… Stateful Rules – If an inbound request is allowed, the outbound response is automatically allowed.
βœ… Default Deny Policy – All traffic is blocked unless explicitly allowed.
βœ… Can Be Attached to Multiple Instances – One Security Group can be associated with multiple EC2 instances.


πŸ”Ή Step 1: Log in to the AWS Console

  1. Open AWS Management Console.

  2. Log in using your AWS account credentials.

  3. Navigate to the EC2 Dashboard by searching for β€œEC2” in the AWS Services tab.


πŸ”Ή Step 2: Navigate to Security Groups

  1. In the EC2 Dashboard, look for Network & Security in the left-hand menu.

  2. Click on Security Groups.

  3. Click Create Security Group to define a new firewall policy for your instance.


πŸ”Ή Step 3: Create a New Security Group

  1. Enter Security Group Name – Choose a meaningful name (e.g., WebServer-SG).

  2. Description – Describe its purpose (e.g., β€œSecurity Group for Web Server”).

  3. Select VPC – Choose your VPC (default VPC is fine).


πŸ”Ή Step 4: Configure Inbound Rules

Inbound rules define who can access your instance.

Common Inbound Rules for DevOps

ProtocolPortSourcePurpose
SSH22My IPSecure remote access
HTTP80Anywhere (0.0.0.0/0)Web traffic
HTTPS443Anywhere (0.0.0.0/0)Secure web access
MySQL3306Custom IPDatabase connection

πŸ”Ή Steps to Add Inbound Rules

  1. Click Add Rule.

  2. Choose a protocol (e.g., SSH, HTTP, HTTPS).

  3. Specify the port number (e.g., 22 for SSH, 80 for HTTP).

  4. Select the source:

    • My IP – Best for SSH (secures access to your IP only).

    • Anywhere (0.0.0.0/0) – Allows access from any IP (use with caution).

    • Custom – Define a specific IP or CIDR range.

  5. Click Save Rules.


πŸ”Ή Step 5: Configure Outbound Rules

Outbound rules define what traffic your instance can send out.

Default Outbound Rule

AWS allows all outbound traffic by default so instances can connect to external services.

  1. Click the Outbound Rules tab.

  2. Modify rules if needed (e.g., restrict access to a specific IP).

  3. Click Save Rules.


πŸ”Ή Step 6: Attach the Security Group to an EC2 Instance

Once the Security Group is created, you need to attach it to an EC2 instance.

  1. Go to the EC2 Dashboard β†’ Click Instances.

  2. Select your instance β†’ Click Actions β†’ Security β†’ Change Security Groups.

  3. Select the Security Group you created and click Save.


πŸ”Ή Step 7: Test Your Security Group Configuration

πŸ” Test SSH Access

ssh -i your-key.pem ec2-user@your-instance-ip

βœ”οΈ If the SSH rule is configured correctly, you should be able to log in.

πŸ” Test HTTP/HTTPS Access

πŸ” Test Database Connection

  • Use MySQL CLI or a database client to connect using:

      mysql -h your-instance-ip -u username -p
    

βœ”οΈ If connected, the database access rule is correct.


βœ… Best Practices for Security Groups

πŸš€ Follow the Principle of Least Privilege – Only open necessary ports.
πŸ”’ Restrict SSH to Your IP – Avoid 0.0.0.0/0 for security.
πŸ”„ Use Security Groups Instead of IPs – Allow access from other Security Groups instead of static IPs.
πŸ“‹ Audit Security Groups Regularly – Remove unused rules to reduce attack surfaces.


πŸš€ Conclusion

Security Groups are an essential part of AWS security. Properly configuring them ensures your cloud infrastructure remains protected while allowing necessary access.

πŸ“Œ Today, I successfully created and configured a Security Group in AWS as part of my #90DaysOfDevOps journey!

πŸ“’ What are your thoughts on Security Groups? Have you faced any challenges configuring them? Let’s discuss in the comments! πŸ‘‡

Β