Create Security Group

VPC Security Group

A subnet group is a collection of subnets running on Amazon Virtual Private Cloud (VPC) environment, allows you configure inbound and outbound rules

Create VPC Security Groups

In this step, we will create two Security Groups (SGs): one for public subnets (used by EC2 instances) and one for private subnets (DocumentDB)

2.1. Create Public Security Group (SG Public - EC2)

  • Go to Security groups and select Create security group security-groups

  • 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 basic-details

  • Add the following Inbound Rules for public-sg-ec2

    ProtocolPort RangeSourceMô tả
    HTTP800.0.0.0/0Cho phép truy cập website
    HTTPS4430.0.0.0/0Hỗ trợ SSL/TLS
    SSH220.0.0.0/0Đăng nhập SSH vào EC2
    Custom TCP30000.0.0.0/0Chạy Node.js và Express
    Custom TCP27017SG-Private-DocumentDBCho phép EC2 kết nối DocumentDB
    Custom TCP88000.0.0.0/0Chạy server trên cổng 8800

    inbound-rules

  • Allow all Outbound traffic and select Create security group outbound-rules public-sg

2.2. Create Private Security Group (SG Private - DocumentDB)

  • 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 basic-details

  • Add the following Inbound Rules for private-sg-documentdb

ProtocolPort RangeSourceDescription
Custom TCP27017SG-Public-EC2Only EC2 can access DocumentDB

inbound-rules

  • Allow all Outbound traffic and select Create security group outbound-rules public-sg

2.3 Add Inbound Rules for Port 27017 in public-sg-ec2

  • In the Security Groups interface, select public-sg-ec2 public-sg-ec2

  • Then, select Edit inbound rules to add an inbound rule add-inbound

  • Add the inbound rule and select Save rules inbound inbound-rules