DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Unlocking the Benefits of a Private API in AWS API Gateway
  • AWS WAF Classic vs WAFV2: Features and Migration Considerations
  • Processing Cloud Data With DuckDB And AWS S3
  • AWS Nitro Enclaves: Enhancing Security With Isolated Compute Environments

Trending

  • How to Build Scalable Mobile Apps With React Native: A Step-by-Step Guide
  • The Transformative Power of Artificial Intelligence in Cloud Security
  • On-Call That Doesn’t Suck: A Guide for Data Engineers
  • Filtering Messages With Azure Content Safety and Spring AI
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. AWS Security Groups Basics

AWS Security Groups Basics

A Security Group is a virtual firewall for your EC2 instance to control Inbound/Outbound traffic to/from your instance.

By 
Jawad Hasan Shani user avatar
Jawad Hasan Shani
DZone Core CORE ·
Apr. 23, 21 · Tutorial
Likes (6)
Comment
Save
Tweet
Share
10.0K Views

Join the DZone community and get the full member experience.

Join For Free

Introduction

Security Groups are one of the fundamental concepts you need to learn when you are setting up infrastructure in AWS. Having a good understanding of their workings will help you not only design proper access for your EC2 instances but you will be also able to quickly spot and deal with issues with existing designs.

We have been using security groups in the earlier posts in this series and today we will learn a little bit more about those.

In my previous post on AWS Basics: Bastian Hosts and NATS, we used security groups to manage access to EC2 instances.

Here is the architecture diagram for reference. As you can see that it already has a few security groups set up which control access to different instances.

Reference Architecture Diagram

Security Groups in AWS

A Security Group is a virtual firewall for your EC2 instance to control Inbound/Outbound traffic to/from your instance.

A Security group is made up of a set of inbound and outbound rules.

A security group that belongs to a VPC and is assigned at the instance level and can be shared among many instances. You can use the same Security Group in different subnets in the same VPC. Subnets can also have different Security Groups.

Security Groups allow access. They do not use the word deny, yet they implicitly deny. For example, I need access to my webserver through port 80. I am allowing access through port 80. Am I allowing access through port 90? Not, if it is not listed. So, implicitly denying, you can’t get to port 90 or any other port unless it is listed as a rule.

You can even set security group rules to allow access from other security groups instead of by IP address(s).

They are stateful in design. If you think of A as coming in and B going out, well... inbound traffic is noted. If the traffic got in, it gets back out. if the traffic goes out, it gets back in.

As mentioned earlier, security groups are assigned to the instance. Security groups are firewalls and they are protecting the network interface cards of that instance. They are controlling packet flow.

AWS Cloud VPC Subnets Diagram

Traffic Flow to Instance

Let’s look at traffic flow to individual instances to understand how security groups fit in:

  1. Internet or VPN
  2. Router
  3. Route-Table
  4. Network Access Control List (NACL)
  5. Security Group (SG)

If traffic is allowed by the Inbound rule, then and only then, it will go to the instance.

Create Security Group

We can create security groups from the VPC dashboard:

Creating Security Groups From VPC Dashboard

Security Group Rules

We learned earlier that a security group is a set of inbound/outbound rules.

When creating the rule, you can also specify the Type (e.g TCP), Port, along with source or destination. Following picture shows Inbound Rules example:

Inbound Rules Example

You can see that in the example, few Inbound rules are allowing incoming traffic, on certain ports from a certain source(s) (in this example from anywhere in the world).

Following picture show an example for Outbound rules:

Outbound Rules Example

Here, in this example, we have a single outbound rule, which is allowing 'All traffic' to any destination.

In this example, both types of these Inbound/Outbound rules are defined in the same security group and when attaching to an EC2 instance, they act as a firewall for incoming/outgoing traffic.

Source/Destination

Given a rule, you can specify a few different things as source or destination of a rule:

  • Security Group: First, you can define a security group (ID of another sg) in your VPC or a peered VPC (start typing sg to see options).
  • IP Address: Next, you can have an IP address or a range of IP addresses from a certain subnet in your VPC. It can also be a single IP address of a particular machine that needs to have access (use /32 for a single IPV4 address).

When you set a Security Group as a source/destination; you are saying that any machine that is assigned to that security group can have access over the port or protocol that you defined and allowed through that rule.

Outbound rules follow the same format (called destination instead of source).

Use the description field for documentation. It is good when dealing with IPs or when reviewing your security groups to understand its purpose e.g.:

Inbound Rules Tab Screenshot

Summary

Security Groups allow (deny) access. They are virtual firewalls for your EC2 instances. They are stateful in design (unlike NACL, which is stateless). Let me know if you have any comments or questions. Till next time, Happy Coding!

AWS security

Published at DZone with permission of Jawad Hasan Shani. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Unlocking the Benefits of a Private API in AWS API Gateway
  • AWS WAF Classic vs WAFV2: Features and Migration Considerations
  • Processing Cloud Data With DuckDB And AWS S3
  • AWS Nitro Enclaves: Enhancing Security With Isolated Compute Environments

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!