Advanced01:15:00
Peer VPC with Transit Gateway and its components
- Click on the Open Console button, and you will get redirected to AWS Console in a new browser tab.
- On the AWS sign-in page, Leave the Account ID as default. Never edit/remove the 12-digit Account ID present in the AWS Console. Otherwise, you cannot proceed with the lab. Now copy your User Name and Password in the Lab Console to the IAM Username and Password in AWS Console and click on the Sign in button.
- On the AWS sign-in page,
- Leave the Account ID as default. Never edit/remove the 12-digit Account ID present in the AWS Console. Otherwise, you cannot proceed with the lab.
- Now copy your User Name and Password in the Lab Console to the IAM Username and Password in AWS Console and click on the Sign in button.
- Once Signed In to the AWS Management Console, make the default AWS Region as US East (N. Virginia) us-east-1.
- In this task, we are going to create the first VPC (Virtual Private Cloud) in the specified AWS region. This VPC will serve as one of the VPCs that will be peered using the Transit Gateway.
- Make sure you are in the N.Virginia Region.
- Navigate to VPC by clicking on the Services menu in the top, then click on VPC in the Networking & Content Delivery section.
- Navigate to Your VPCs on the left panel and click on the Create VPC button. Select VPC only Name tag : Enter First_VPC IPv4 CIDR block : Enter 10.0.0.0/24

- Navigate to Your VPCs on the left panel and click on the Create VPC button.
- Select VPC only
- Name tag : Enter First_VPC
- IPv4 CIDR block : Enter 10.0.0.0/24

- Task 2: Create the first VPC

- Leave everything else as default and click on the Create VPC button.
- You have successfully created the VPC. Note the VPC ID for later use.
- Task 2: Create the first VPC

- Now select the First_VPC from the list and click on the Actions dropdown and select Edit VPC Settings
- Check the Enable DNS resolution and Enable DNS hostnames checkbox under DNS settings, and then click on the Save button.

- Task 2: Create the first VPC

- In this task, we are going to create a public subnet within the first VPC. The public subnet will be used for launching an EC2 instance that will be accessible over the internet.
- Navigate to Subnet from the left side menu and click on Create subnet button. VPC ID : Select the First_VPC VPC from the list. Subnet name : Enter Public_subnet_first_VPC Availability Zone : Leave as No Preference IPv4 CIDR block : Enter 10.0.0.0/25
- Navigate to Subnet from the left side menu and click on Create subnet button.
- VPC ID : Select the First_VPC VPC from the list.
- Subnet name : Enter Public_subnet_first_VPC
- Availability Zone : Leave as No Preference
- IPv4 CIDR block : Enter 10.0.0.0/25
- Now click on the Create subnet button.
- In this task, we are going to create an internet gateway and attach it to the first VPC. The internet gateway allows the EC2 instance in the public subnet to communicate with the internet.
- Navigate to the Internet gateways from the left side menu and click on the Create Internet gateway button. Name tag : Enter IGW
- Navigate to the Internet gateways from the left side menu and click on the Create Internet gateway button.
- Name tag : Enter IGW
- Click on the Create Internet gateway button
- Now click on the Actions dropdown and select Attach to VPC. Available VPCs : select First_VPC from the list.
- Now click on the Actions dropdown and select Attach to VPC.
- Available VPCs : select First_VPC from the list.
- Now click on the Attach Internet gateway.
- Task 4: Create and attach an Internet Gateway

- In this task, we are going to create a public route table and associate it with the public subnet. The route table controls the traffic between the subnet and the internet gateway.
- Navigate to Route tables on the left side panel and click on the Create route table. Name : Enter PublicRT VPC* : Select the First_VPC from the list.
- Navigate to Route tables on the left side panel and click on the Create route table.
- Name : Enter PublicRT
- VPC* : Select the First_VPC from the list.
- Now click on the Create route table.
- Switch to the Subnet associations tab in below.
- Click on the Edit subnet associations.
- Now select the subnet with name Public_subnet_first_VPC and click on the Save associations button.
- Task 5: Create a Public Route Table and associate it with the subnet

- In this task, we are going to add a public route in the route table to allow traffic from the public subnet to the internet. This enables the EC2 instance in the public subnet to communicate with resources outside the VPC.
- Navigate to Route tables on the left side panel and select the PublicRT from the list.
- Switch to the Routes tab in below and click on the Edit routes.
- Now click on the Add route Destination : Enter 0.0.0.0/0 Target : select Internet Gateway and then select the Internet Gateway id present.
- Now click on the Add route
- Destination : Enter 0.0.0.0/0
- Target : select Internet Gateway and then select the Internet Gateway id present.
- Click on the Save changes.
- Task 6: Add public Route in the Route table

- In this task, we are going to launch an EC2 instance in the first VPC's public subnet. This EC2 instance will be used to test the connectivity between the VPCs after peering them using the Transit Gateway.
- Make sure you are in the N. Virginia(us-east-1) Region.
- Navigate to EC2 by clicking on the Services menu in the top left, then click on EC2 in the Compute section.
- Navigate to Instances from the left side menu and click on Launch Instances button.
- Task 7: Launch an EC2 instance in the First VPC

- Under the Name and tags section : Name : First_VPCs_EC2
- Under the Name and tags section :
- Name : First_VPCs_EC2
- Under the Application and OS Images (Amazon Machine Image) section :
- Select Quick Start tab and Amazon Linux 2023 kernel-6.1 AMI under it

- Under the Instance Type section :
- Instance Type : Select t2.micro

- Under the Key Pair (login) section :
- Click on Create new key pair hyperlink
- Key pair name: ec2_ssh_key
- Key pair type: RSA
- Private key file format: .pem
- Click on Create key pair and select the created key pair
- Under the Network Settings section :
- Click on Edit button
- VPC : Select First_VPC
- Subnet : leave as default
- Auto-assign public IP: select Enable
- Firewall (security groups) : Select Create a new security group
- Security group name : Enter Public_EC2_SG
- Description : Enter Security group for public EC2
- To add SSH: Choose Type: SSH Source: Anywhere (From ALL IP addresses accessible).
- To add SSH:
- Choose Type: SSH
- Source: Anywhere (From ALL IP addresses accessible).
- For HTTP, click on Add security group rule, Choose Type: HTTP Source: Anywhere (From ALL IP addresses accessible).
- For HTTP, click on Add security group rule,
- Choose Type: HTTP
- Source: Anywhere (From ALL IP addresses accessible).
- For HTTPS, click on Add security group rule, Choose Type: HTTPS Source: Anywhere (From ALL IP addresses accessible).
- For HTTPS, click on Add security group rule,
- Choose Type: HTTPS
- Source: Anywhere (From ALL IP addresses accessible).
- Under the Advanced details section : Under the IAM instance profile: Select task232_profile_... role. Under the User data: copy and paste the following script to create an HTML page served by an Apache httpd web server. Make sure you remove the extra space after pasting the comment.
- Under the Advanced details section :
- Under the IAM instance profile: Select task232_profile_... role.
- Under the User data: copy and paste the following script to create an HTML page served by an Apache httpd web server. Make sure you remove the extra space after pasting the comment.
- Keep everything else as default and click on the Launch instance button.
- Launch Status: Your instance is now launching, Navigate to Instances page from the left menu and wait until the status of the EC2 Instance changes to running.
- Task 7: Launch an EC2 instance in the First VPC

- Note down the sample IPv4 Public IP Address of the EC2 instance. A sample is shown in the screenshot below.
- Task 7: Launch an EC2 instance in the First VPC

- If you paste the IPv4 Public IP in your browser and hit [enter]. You will be able to the below webpage.
- Task 7: Launch an EC2 instance in the First VPC

- In this task, we are going to create the second VPC, which will be the other VPC that is peered with the first VPC using the Transit Gateway.
- Navigate to VPC by clicking on the Services menu at the top, then click on VPC in the Networking & Content Delivery section.
- Navigate to Your VPCs on the left panel and click on the Create VPC button. Select VPC only Name tag : Enter Second_VPC IPv4 CIDR block : Enter 20.0.0.0/24

- Navigate to Your VPCs on the left panel and click on the Create VPC button.
- Select VPC only
- Name tag : Enter Second_VPC
- IPv4 CIDR block : Enter 20.0.0.0/24

- Task 8: Create a Second VPC

- Leave everything else as default and click on the Create VPC button.
- You have successfully created the VPC. Note the VPC ID for later use.
- Task 8: Create a Second VPC

- Now select the Second_VPC from the list and click on the Actions and select Edit VPC settings
- Check the Enable DNS resolution and Enable DNS hostnames checkbox under DNS settings and then click on the Save button
- In this task, we are going to create a private subnet within the second VPC. The private subnet will be used for launching an EC2 instance that will not have direct internet connectivity.
- Navigate to Subnets from the left side menu and click on Create Subnet button.
- VPC ID : Select the Second_VPC VPC from the list.
- Subnet name : Enter Private_subnet_second_VPC
- Availability Zone : Leave as No Preference
- IPv4 CIDR block : Enter 20.0.0.0/25
- Now click on the Create subnet button
- In this task, we are going to launch an EC2 instance in the second VPC's private subnet. This EC2 instance will be used to test the connectivity between the VPCs after peering them using the Transit Gateway.
- Now again click on Launch Instances button.
- Under the Name and tags section :
- Name : Second_VPCs_EC2
- Under the Application and OS Images (Amazon Machine Image) section :
- Select Quick Start tab and Amazon Linux 2023 kernel-6.1 AMI under it

- Under the Instance Type section : Instance Type : Select t2.micro

- Under the Instance Type section :
- Instance Type : Select t2.micro

- Under the Key Pair (login) section :
- Select ec2_ssh_key from the list.
- Under the Network Settings section :
- Click on Edit button
- VPC : Select Second_VPC
- Subnet : leave as default
- Auto-assign public IP: select Disable
- Firewall (security groups) : Select Create a new security group
- Security group name : Enter Private_EC2_SG
- Description : Enter Security group for private EC2
- To add SSH: Choose Type: SSH Source: Anywhere (From ALL IP addresses accessible).
- To add SSH:
- Choose Type: SSH
- Source: Anywhere (From ALL IP addresses accessible).
- Keep everything else as default and then click on the Launch Instance button.
- Your instances are now launching. Navigate to the EC2 instance page and wait until the status changes to the Running. It will usually take 1-2 minutes.
- Task 10: Launch an EC2 instance in Second VPC

- Since this EC2 is created in a private subnet, the machine will only have Private IP so, note down the sample IPv4 Private IP Address of the EC2 instance. A sample is shown in the screenshot below.
- Task 10: Launch an EC2 instance in Second VPC

- In this task, we are going to create a Transit Gateway, which acts as a central hub for connecting multiple VPCs and on-premises networks. The Transit Gateway simplifies the network architecture and facilitates the peering between VPCs.
- Navigate to VPC by clicking on the Services menu at the top, then click on VPC in the Networking & Content Delivery section.
- Click on the Transit Gateways present under Transit Gateways section on the left sidebar.
- Click on the Create Transit gateway button to create a Transit gateway.
- Task 11: Create a Transit gateway

- Name tag: Enter DemoTG
- Description: Enter TG for peering two VPCs
- Keep all the options as default and click on Create transit gateway button.
- Currently, the status of the Transit gateway is in a pending state. It takes up to 5 minutes for it to become available.

- Task 11: Create a Transit gateway

- In this task, we are going to create two Transit Gateway attachments, one for each of the VPCs created. These attachments establish the peering between the VPCs and the Transit Gateway.
- Navigate to the Transit gateways attachments present under Transit Gateways section on the left side bar.
- Click on the Create transit gateway attachment button Name tag : First_VPC_TGA Transit Gateway ID: Select transit gateway present with Name tag DemoTG. Attachment type: Select VPC DNS support: Checked (default) IPv6 support: Unchecked VPC ID: Select VPC with the Name First_VPC Subnet IDs: Default
- Click on the Create transit gateway attachment button
- Name tag : First_VPC_TGA
- Transit Gateway ID: Select transit gateway present with Name tag DemoTG.
- Attachment type: Select VPC
- DNS support: Checked (default)
- IPv6 support: Unchecked
- VPC ID: Select VPC with the Name First_VPC
- Subnet IDs: Default
- Click on the Create transit gateway attachment.
- Creation will be in-progress for the Transit gateway attachment.
- It takes upto 5 minutes for it to come in available state.
- To create the Transit gateway attachment for the second VPC, Click on the Create transit gateway attachment Name tag: Second_VPCs_TGA Transit Gateway ID: Select transit gateway present with Name tag DemoTG. Attachment type: Select VPC DNS support: Checked (default) IPv6 support: Unchecked VPC ID: Select VPC with the Name Second_VPC Subnet IDs: Default
- To create the Transit gateway attachment for the second VPC, Click on the Create transit gateway attachment
- Name tag: Second_VPCs_TGA
- Transit Gateway ID: Select transit gateway present with Name tag DemoTG.
- Attachment type: Select VPC
- DNS support: Checked (default)
- IPv6 support: Unchecked
- VPC ID: Select VPC with the Name Second_VPC
- Subnet IDs: Default
- Creation will be in-progress for the Transit gateway attachment.
- Once created both the Transit gateway attachment will be present.

- Task 12: Create two Transit gateway attachment for the VPCs created

- In this task, we are going to add a route in the first VPC's route table that directs traffic destined for the second VPC's CIDR range to the Transit Gateway. This enables communication between the VPCs through the Transit Gateway.
- Navigate to Route tables on the left side panel.
- There will be 4 route tables present, and to avoid confusion put the entry in the correct route table. Let's filter the route table present using the VPC filter.
- For the First VPC you created, you also have created a Route table with the name PublicRT which has a subnet association. Here the PublicRT route table is also called a custom or non-default route table.
- Click on the Route table ID to see the routes present.
- Click on the Routes tab below and click on the Edit routes.
- For this Route table, there are two entries present, First the local entry i.e. CIDR block of the First VPC, the second entry is about the route to the internet with Destination as 0.0.0.0/0 having target as the Internet gateway.
- Let’s add the third route which has destination as 20.0.0.0/24 i.e. CIDR range of second VPC and Target as Transit gateway.
- To add the third route, Click on the Add route. Destination: Enter 20.0.0.0/24 Target: Enter Transit Gateway
- To add the third route, Click on the Add route.
- Destination: Enter 20.0.0.0/24
- Target: Enter Transit Gateway
- Click on the Save changes button.
- Make sure Routes have Destination as 20.0.0.0/24

- Note: Sometimes it does not show the destination as 20.0.0.0/24, in that case, please add the following from Step 6 of this task.
- In this task, we are going to add a route in the second VPC's route table that directs traffic destined for the first VPC's CIDR range to the Transit Gateway. This allows communication between the VPCs through the Transit Gateway.
- Navigate to Route tables on the left side panel.
- Filter the VPC’s by using the ID of the second VPC.
- In the second VPC, we have not created any extra route table, so there will be only one route table present which was created during the creation of VPC itself and it’s called a default route table or main route table.
- Let's filter the route table present using the VPC filter.
- To get the filter using the VPC option, simply click on the search bar and it will show the different options for the filter. Select VPC from that list and choose the ID of Second VPC.
- Click on the Route table ID to see the routes present.
- Click on the Routes tab in below and click on the Edit routes.
- There will be only one entry to local, as we have not created an internet gateway because this is a private route table.
- Task 14: Add the routes in the Second VPC’s route table

- Let’s add the entry to 10.0.0.0/24 i.e. CIDR of the first VPC as a destination and Transit gateway as a target.
- To get the Transit gateway ID, click on the search button and select Transit Gateway from the list of options present.

- Click on the Save changes button.
- Make sure Routes have Destination as 10.0.0.0/24

- Note: Sometimes it does not show the destination as 10.0.0.0/24, in that case, please add the following from Step 5 of this task.
- In this task, we are going to test the connectivity between the EC2 instances in both VPCs. This step confirms that the VPCs have been successfully peered using the Transit Gateway, and the EC2 instances can communicate with each other.
- You have copied the IPv4 Public IP of the EC2 instance created in the First VPC.
- Please follow the steps for the Session Manager to connect to First_VPCs_EC2Select First_VPCs_EC2 and click on the Connect button.Go to SSM Session Manager and click Connect


- Please follow the steps for the Session Manager to connect to First_VPCs_EC2
- Select First_VPCs_EC2 and click on the Connect button.

- Go to SSM Session Manager and click Connect

- Once you have successfully connected in to EC2, run the following commands :
- Switch to root user :sudo su
- Switch to root user :
- Update server repository :sudo dnf update -y
- Update server repository :
- Now we need to copy the .pem key of the EC2 instance created.
- Create a file :nano ec2_ssh_key.pem
- Create a file :
- Task 15: Test the connectivity between two VPCs

- Open the .pem key of EC2 ec2_ssh_key in your local editor and paste it in the terminal file.

- Press [ctrl] + x / [control] + x
- Press y key in your keyboard.
- File Name : No changes, press [Enter] key in your keyboard
- Change the .pem key permissionchmod 400 ec2_ssh_key.pem
- Change the .pem key permission
- SSH into the Private EC2 ec2_ssh_keyssh ec2-user@<IPv4 private Ip> -i ec2_ssh_key.pem
- SSH into the Private EC2 ec2_ssh_key
- Copy the Private IP of Second_VPCs_EC2
- Example : ssh [email protected] -i ec2_ssh_key.pem
- If the connection prompts a message to confirm connect enter yes
- Task 15: Test the connectivity between two VPCs

- As you can see the IP address is changed to private ec2 private IP 30.0.1.154
- Task 15: Test the connectivity between two VPCs

- Now you have connected two VPCs using the Transit gateway.
- With Transit Gateway, you can easily add or remove VPC connections as your network grows or changes, without impacting existing connections. It provides a flexible and scalable solution for interconnecting VPCs and simplifies network administration, routing, and security.
- Once the lab steps are completed, please click on the Validation button on the left side panel.
- This will validate the resources in the AWS account and displays whether you have completed this lab successfully or not.
- Sample output :

- Task 16: Validation Test

- Make sure you are in the US East (N. Virginia) Region.
- Navigate to EC2 by clicking on the Services menu in the top left, then click on EC2 in the Compute section.
- Now select both the EC2 instances that you have created, click on Instance State and click on the Terminate instance option.
- Task 17: Delete AWS Resources

- Click on the Terminate button and your EC2 will start terminating.
- You have successfully created a VPC with a public subnet & internet gateway and Launched an EC2 instance.
- You have successfully created a VPC with a private subnet and Launched an EC2 instance.
- You have successfully created the Transit gateway.
- You have successfully created the Transit gateway attachments for both the VPC’s.
- You have successfully tested the connectivity of VPC after peering using the Transit gateway.
- Sign out of AWS Account.
- You have successfully completed the lab.
- Once you have completed the steps, click on End Lab from the lab console.