A Security Group is a set of rules that control inbound and outbound network traffic for instances in an Amazon VPC. It acts as a virtual firewall, managing and protecting resources.
Next, we will create two Security Groups (SGs) representing public subnets (EC2) and private subnets (DocumentDB).
public-sg-ec2
Public Security Group for EC2
Protocol | Port Range | Source | Description |
---|---|---|---|
HTTP | 80 | 0.0.0.0/0 | Allow website access |
HTTPS | 443 | 0.0.0.0/0 | Enable SSL/TLS |
SSH | 22 | 0.0.0.0/0 | SSH access to EC2 |
Custom TCP | 3000 | 0.0.0.0/0 | Run Next.js in dev mode |
Custom TCP | 27017 | SG-Private-DocumentDB | Allow EC2 to connect to DocumentDB |
❗❗ Add Inbound rule for port 27017 later
private-sg-documentdb
Private Security Group for DocumentDB
Protocol | Port Range | Source | Description |
---|---|---|---|
Custom TCP | 27017 | SG-Public-EC2 | Only EC2 can access DocumentDB |
In the Security Groups interface, select public-sg-ec2
Then, select Edit inbound rules to add an inbound rule
Add the inbound rule and select Save rules