Kiến trúc xây dựng gồm các thành phần sau:
- VPC
- 2 Public subnet
- 2 Private subnet
- Internet Gateway
- NAT Gateway
- S3 VPC Endpoint
- Public Route Table
- Private Route Table
- Bastion host
- Web server
Sau khi xây dựng xong chúng ta sẽ tiến hành ssh đến Bastion host sau đó ssh đến Web server
Tại Web server ở Private Subnet, chúng ta thực hiện
- Test đi ra Internet
- Access đến S3 thông qua VPC Gateway Endpoint
Lưu ý
1. Create VPC
Chúng ta sẽ tạo VPC với các thành phần như: VPC + IGW + Subnet + Route Table + NAT
Tại Console VPC -> Click Create VPC
VPC settings
- Resources to create:
VPC and more
- Auto-generate:
check
- Tên:
d-vpc-saa-001
- IPv4 CIDR block:
10.0.0.0/16
- Number of Availability Zones (AZs) :
2
- Number of public subnets:
2
- Number of private subnets:
2
- NAT gateways ($):
In 1 AZ
- VPC endpoints:
S3 Gateway
- Còn lại để default

Đợi 1 lúc để việc create VPC hoàn thành. 
2. Create Bastion host
Bastion host là EC2
- Đặt ở Public subnet
- Cho phép SSH từ local
- Có vai trò là máy trung gian để ssh đến các EC2 khác trong Private subnet

2.1 Create Security Group cho Bastion host
- Name:
d-sg-SAA-vpc-basion-host
- Description:
Allow ssh from internet
- VPC:
d-vpc-saa-001-vpc
- Inbound rules
Type | Protocol | Port range | Source |
---|
SSH | TCP | 22 | 0.0.0.0/0 |
- Outbound rules
Type | Protocol | Port range | Source |
---|
All traffic | All | All | 0.0.0.0/0 |
- Tags
Key | value |
---|
Name | d-sg-SAA-vpc-basion-host |
2.2 Create EC2
- Name:
d-ec2-SAA-vpc-bastion-host
- OS: Default (Amazon Linux 2023)
- Instance type: Default (t2.micro)
- Key pair:
d-key-SAA-common
(Nếu chưa có thì tạo mới) - Network Setting:
- VPC:
d-vpc-saa-001-vpc
- Subnet:
d-vpc-saa-001-subnet-public1-us-east-1a
- Auto-assign public IP:
Enable
- Select existing security group:
d-sg-SAA-vpc-basion-host

3. Create Web server đặt ở Private Subnet
3.1 Create Security Group cho private instance
- Name:
d-sg-SAA-vpc-private-instance
- Description:
Allow ssh from bastion host
- VPC:
d-vpc-saa-001-vpc
- Inbound rules
Type | Protocol | Port range | Source |
---|
SSH | TCP | 22 | Chọn SG của bastion host |
- Outbound rules
Type | Protocol | Port range | Source |
---|
All traffic | All | All | 0.0.0.0/0 |
- Tags
Key | value |
---|
Name | d-sg-SAA-vpc-private-instance |
3.2 Create private EC2
- Name:
d-ec2-SAA-vpc-private-instance
- OS: Default (Amazon Linux 2023)
- Instance type: Default (t2.micro)
- Key pair:
d-key-SAA-common
(Nếu chưa có thì tạo mới) - Network Setting:
- VPC:
d-vpc-saa-001-vpc
- Subnet:
d-vpc-saa-001-subnet-private1-us-east-1a
- Auto-assign public IP:
Disable
- Select existing security group:
d-sg-SAA-vpc-private-instance

4. Đứng ở Bastion host ssh qua private instance
4.1 ssh đến bastion host

4.2 Tạo Keypair pem file để access tới private instance
4.3 ssh đến private instance:
Đứng tại bastion và run lệnh dưới: (nhớ thay giá trị web server private instance IP)
ssh -i "d-key-SAA-common.pem" ec2-user@{web server private instance IP}

5. Testing: "curl google.com"
Tại Web server, run lệnh:
Kết quả trả về như hình bên dưới xem như private instance đã đi dc Internet 
6. Modify IAM role để có thể access tới S3 từ private instance
Sử dụng lại role: SAAEC2S3FullAccessRole
đã tạo ở Bài EC2 Fundamentals 
7. Testing: "aws s3 ls"
Confirm access dc đến S3

Clean up
Xóa lần lượt các resource theo thứ tự sau:
Delete NAT Gateway: d-vpc-saa-001-nat-public1-us-east-1a
Terminated 2 EC2: d-ec2-SAA-vpc-bastion-host
và d-ec2-SAA-vpc-private-instance
Release Elastic IP address: d-vpc-saa-001-eip-us-east-1a
(NAT Gateway phải ở status Deleted
thì mới Release dc EIP)

Delete VPC
