Kiến trúc xây dựng gồm các thành phần sau:
- VPC A
- Internet Gateway
- 1 Public subnet
- Public Route Table
- VPC B
- Internet Gateway
- 1 Public subnet
- Public Route Table
- 2 EC2 ở 2 VPC
Sau khi xây dựng xong chúng ta sẽ tiến hành test kết nối từ Server A đến Server B.
Lưu ý
Create VPC
VPC A
- Resources to create:
VPC and more
- Auto-generate:
check
- Tên:
d-vpc-saa-01
- IPv4 CIDR block:
10.1.0.0/16
- Number of Availability Zones (AZs) :
1
- Number of public subnets:
1
- Number of private subnets:
0
- NAT gateways ($):
None
- VPC endpoints:
None
- Còn lại để default

VPC B
- Resources to create:
VPC and more
- Auto-generate:
check
- Tên:
d-vpc-saa-02
- IPv4 CIDR block:
10.2.0.0/16
- Number of Availability Zones (AZs) :
1
- Number of public subnets:
1
- Number of private subnets:
0
- NAT gateways ($):
None
- VPC endpoints:
None
- Còn lại để default

Create VPC peering connection
Để thực hiện kết nối 2 vpc với nhau thì sẽ thực hiện tạo vpc connection
Vào VPC console -> Peering connection -> Create peering connection 
Điền các thông tin cho vpc peering connection và nhấn Create peering connection
- Name:
d-peering-saa-vpc01-and-vpc02
- Requester:
d-vpc-saa-01-vpc
- Accepter:
d-vpc-saa-02-vpc

VPC peering đã được tạo, tuy nhiên đang ở trạng thái Pending acceptance
, sau khi tạo xong phải confirm chấp nhận thì mới được 
VPC peering đã tạo xong 
Update route table của 2 VPC
Update route table cho vpc 1

Route table name: d-vpc-saa-01-rtb-public
Destination | Target | Note |
---|
0.0.0.0/0 | igw-xxxxxxxx | Route mặc định, không chỉnh sửa |
10.1.0.0/16 | local | Route mặc định, không chỉnh sửa |
10.2.0.0/16 | pcx-xxxxxxxx | Chọn peering connection đã tạo |
Bấm save change để lưu lại
Update route table cho vpc 2
Thực hiện tương tự như trên 
Route table name: d-vpc-saa-02-rtb-public
Destination | Target | Note |
---|
0.0.0.0/0 | igw-xxxxxxxx | Route mặc định, không chỉnh sửa |
10.2.0.0/16 | local | Route mặc định, không chỉnh sửa |
10.1.0.0/16 | pcx-xxxxxxxx | Chọn peering connection đã tạo |
Bấm save change để lưu lại
Tạo ec2 ở cả 2 vpc
Create security group cho ec2 ở VPC: d-vpc-saa-01-vpc
- Name:
d-sg-saa-01
- Description:
Allow all connection
- VPC:
d-vpc-saa-01-vpc
- Inbound rules
Type | Protocol | Port range | Source |
---|
All ICMP v4 | All | All | 10.2.0.0/16 |
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
Create security group cho ec2 ở VPC: d-vpc-saa-02-vpc
- Name:
d-sg-saa-02
- Description:
Allow all connection
- VPC:
d-vpc-saa-02-vpc
- Inbound rules
Type | Protocol | Port range | Source |
---|
All ICMP v4 | All | All | 10.1.0.0/16 |
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
Tạo EC2 ở VPC: d-vpc-saa-01-vpc
- Name:
d-ec2-saa-01
- 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-01-vpc
- Subnet:
d-vpc-saa-01-subnet-public1-us-east-1a
- Auto-assign public IP:
Enable
- Select existing security group:
d-sg-saa-01
Tạo EC2 ở VPC: d-vpc-saa-02-vpc
- Name:
d-ec2-saa-02
- 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-02-vpc
- Subnet:
d-vpc-saa-02-subnet-public1-us-east-1a
- Auto-assign public IP:
Enable
- Select existing security group:
d-sg-saa-02
Test ping
Để verify được kết nối vpc peering đã hoạt động thì sẽ thực hiện test ping giữa 2 ec2 ở cả 2 vpc.
Thực hiện ssh vào instance ở vpc 1 thông qua instance connect:

Lấy địa chỉ private IP của EC2 2 
Ping đến private ip của instance bên vpc 02
ping <private ip của ec2 bên vpc 02>
Ping thành công !!!
Clean up
Xóa lần lượt các resource theo thứ tự sau:
- Terminated 2 EC2:
d-ec2-saa-01
và d-ec2-saa-02
- VPC peering connection

- Delete VPC:
d-vpc-saa-01-vpc
- Delete VPC:
d-vpc-saa-02-vpc