AWS · explained simply

Security groups, inbound and outbound traffic

A 3-minute hand-drawn animated video with a voice and subtitles. Press play below, or open the .mp4 file.

TL;DR
  • A security group is a guard at your server's door, holding a guest list. AWS calls it a virtual firewall (a filter for network traffic).
  • Inbound = traffic coming in (visitors). Outbound = traffic going out (you going to the shop).
  • Each rule says protocol (how they talk), port (which door number) and source (who may come).
  • Only allow rules exist. Not on the list = dropped. A new group lets nobody in and lets everything out.
  • It is stateful: replies to your own requests come back in, with no inbound rule needed.
0:00 / 3:06

Video file: test_companion/videos/aws-security-groups-excalidraw.mp4 (1920×1080, voice + subtitles).

The ideas

01The picture, part by part

Every AWS word maps to one thing in a housing society from AWS docs

AWS wordIn the pictureWhat it really is
VPCGated societyYour own private network inside AWS.
SubnetA buildingA part of the VPC (a range of IP addresses).
EC2 instanceYour flatYour server.
Security groupGuard at the flat doorFilter on the server: decides which traffic may reach it and leave it.
Inbound ruleGuest list for visitorsWhich traffic may come in.
Outbound ruleWhere you may goWhich traffic may go out.
Network ACLGuard at the society's main gateA second filter for the whole subnet.

Source: AWS docs, vpc-security-groups.html, infrastructure-security.html

02What a rule is

One rule = one line on the guest list from AWS docs

ProtocolPortSourceMeans
TCP800.0.0.0/0Web visits from anyone on the internet.
TCP22203.0.113.0/24Remote login (SSH) only from one address range, like your office.
TCP80, 443lb-sgOnly machines in the load balancer's security group (the "badge" idea).
FactAnswer
Can a rule say "deny"?No. Only allow rules. Not on the list = dropped.
New group: inbound?Nobody can come in (no inbound rules).
New group: outbound?Everything may go out (one allow-all rule).
Many groups on one server?All their rules are joined into one list. Any match lets traffic in.

Source: AWS docs, security-group-rules.html ("Security group rule basics", "Components", "Security group referencing")

03Stateful: the guard remembers

Replies to your own requests get back in from AWS docs

In everyday words
You order a pizza. The delivery person is not on your guest list, but the guard saw you place the order, so they let the pizza in.

AWS docs: if you send a request from an instance, the response traffic for that request is allowed back in whatever the inbound rules say. Replies to allowed inbound traffic may also leave, whatever the outbound rules say.

Source: AWS docs, vpc-security-groups.html ("Security group basics")

04Security group vs network ACL

Two guards, two doors from AWS docs

PointSecurity group (flat door)Network ACL (main gate)
GuardsOne server (instance level)The whole subnet
Rule typesAllow onlyAllow and deny
How it checksLooks at all rules, then decidesIn number order; first match wins
RepliesAuto-allowed (stateful)Need their own rule (stateless)

Source: AWS docs, infrastructure-security.html ("Compare security groups and network ACLs")

Reference

—Sources

WhatWhere
Security group basics, statefuldocs.aws.amazon.com/vpc/latest/userguide/vpc-security-groups.html
Rules: allow only, defaults, parts, referencingdocs.aws.amazon.com/vpc/latest/userguide/security-group-rules.html
Security group vs network ACLdocs.aws.amazon.com/vpc/latest/userguide/infrastructure-security.html
VoicemacOS say, voice Samantha