A subnet group is a collection of subnets running on Amazon Virtual Private Cloud (VPC) environment, allows you configure inbound and outbound rules
In this step, we will create two Security Groups (SGs): one for public subnets (used by EC2 instances) and one for private subnets (DocumentDB)
Go to Security
groups and select
Create security group
In the Create Security Group interface, provide the following details for public-sg-ec2:
Security group name: public-sg-ec2
Description: Public Security Group for EC2
VPC: Select your existing VPC
Add the following Inbound Rules for public-sg-ec2
Protocol | Port Range | Source | Mô tả |
---|---|---|---|
HTTP | 80 | 0.0.0.0/0 | Cho phép truy cập website |
HTTPS | 443 | 0.0.0.0/0 | Hỗ trợ SSL/TLS |
SSH | 22 | 0.0.0.0/0 | Đăng nhập SSH vào EC2 |
Custom TCP | 3000 | 0.0.0.0/0 | Chạy Node.js và Express |
Custom TCP | 27017 | SG-Private-DocumentDB | Cho phép EC2 kết nối DocumentDB |
Custom TCP | 8800 | 0.0.0.0/0 | Chạy server trên cổng 8800 |
Allow all Outbound traffic and select Create security group
In the Create Security Group interface, provide the following details for private-sg-documentdb:
Security group name: private-sg-documentdb
Description: Private Security Group for DocumentDB
VPC: Select your existing VPC
Add the following Inbound Rules for private-sg-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