Understanding Security Groups in AWS EC2

Introduction

Security groups in AWS act as virtual firewalls for EC2 instances, controlling inbound and outbound traffic. Unlike traditional firewalls, security groups only contain allow rules, meaning they define what is permitted, rather than explicitly blocking traffic. In this lecture, we will cover the fundamentals of security groups, their configuration, and best practices.


1. What Are Security Groups?


2. How Security Groups Work

Inbound and Outbound Rules

Example Scenario

  1. A user on the public internet wants to SSH into an EC2 instance.
  2. A security group is attached to the EC2 instance.
  3. The security group rule allows traffic on port 22 from the user’s IP address.
  4. Any unauthorized IP address trying to connect will be blocked.
Type Protocol Port Range Source
SSH TCP 22 My IP (xx.xx.xx.xx)
HTTP TCP 80 0.0.0.0/0 (Anywhere)
HTTPS TCP 443 0.0.0.0/0 (Anywhere)