"Building a Scalable AWS Network Architecture with Transit Gateway"


๐ In this blog, weโll walk through how to connect multiple Amazon VPCs using AWS Transit Gateway, allowing EC2 instances in different VPCs to communicate with each other. This is useful in scenarios where you need scalable, centralized connectivity across multiple VPCs.
๐ Task Breakdown
Here's what we are going to do:
Create 3 different VPCs in the same region
Launch 1 EC2 instance in each VPC
Create a Transit Gateway
Attach all 3 VPCs to the Transit Gateway
Update route tables and security groups
Test connectivity between EC2 instances
๐ ๏ธ Step 1: Create 3 VPCs in the Same Region
Weโll create 3 VPCs with non-overlapping CIDR ranges.
Actions:
Go to VPC Dashboard > Create VPC
Select VPC only option
Create VPCs with following CIDRs:
VPC-1:
10.1.0.0/16
VPC-2:
10.2.0.0/16
VPC-3:
10.3.0.0/16
Enable DNS Hostnames
Repeat the above step for all 3 VPCs.
๐งฑ Step 2 : - Create Subnets for Each VPC
๐น Subnet Creation for VPC-1
Go to: VPC Dashboard > Subnets > Create Subnet
Fill the details:
Name tag:
Sub1
VPC: Select
VPC-1
Availability Zone: e.g.,
ap-south-1a
IPv4 CIDR block:
10.1.0.0/24
Click Create Subnet
Repeat same for:
๐น VPC-2:
Name tag:
Sub2
VPC:
VPC-2
AZ:
ap-south-1a
CIDR:
10.1.2.0/24
๐น VPC-3:
Name tag:
Sub3
VPC:
VPC-3
AZ:
ap-south-1a
CIDR:
0.1.3.0/24
๐ Step 3: Launch EC2 Instances and Configure Subnets
In this step, I launched three EC2 instances and mapped them according to the subnets we created earlier.
๐น Instance Configuration Summary:
Instance | Subnet Type | Public IP Auto-Assign | Purpose |
EC2-1 | Public Subnet | Enabled | Acts as Public Server |
EC2-2 | Private Subnet 1 | Disabled | Backend/Private |
EC2-3 | Private Subnet 2 | Disabled | Backend/Private |
๐ Step 4: Create and Attach Transit Gateway
To enable communication between multiple VPCs, I created a Transit Gateway (TGW) and attached it to all three VPCs.
๐ง Steps Performed:
Created a Transit Gateway from the VPC Dashboard.
Attached the Transit Gateway to the following VPCs:
VPC-1 (contains the public EC2 instance)
VPC-2 (contains private EC2 instance)
VPC-3 (contains another private EC2 instance)
This setup allows centralized routing and enables communication between all EC2 instances across VPCs via the Transit Gateway.
I used this method to avoid the complexity of VPC Peering and simplify inter-VPC networking.
๐ Step 5: Making VPC-1 Public using Internet Gateway
To allow internet access for the EC2 instance in VPC-1, I made one of its subnets public by attaching an Internet Gateway (IGW).
๐ง Steps Performed:
Created an Internet Gateway (IGW).
Attached the IGW to VPC-1.
In the route table of VPC-1, associated only Subnet-1 (which contains the public EC2 instance).
Added a route in the route table with:
Destination:
0.0.0.0/0
Target: Internet Gateway
With this setup, only Subnet-11 has internet access, keeping other subnets private.
๐ Step 6: Configuring Route Tables for Inter-VPC Communication via Transit Gateway
To enable communication between the three VPCs using the Transit Gateway (TGW), I updated each VPCโs route table as follows:
๐ฃ๏ธ VPC-1 Route Table:
Destination: CIDR of VPC-2 โ Target: Transit Gateway
Destination: CIDR of VPC-3 โ Target: Transit Gateway
๐ฃ๏ธ VPC-2 Route Table:
Destination: CIDR of VPC-1 โ Target: Transit Gateway
Destination: CIDR of VPC-3 โ Target: Transit Gateway
๐ฃ๏ธ VPC-3 Route Table:
Destination: CIDR of VPC-1 โ Target: Transit Gateway
Destination: CIDR of VPC-2 โ Target: Transit Gateway
๐ Note: I used each VPCโs CIDR block (e.g.,
10.1.0.0/16
,10.2.0.0/16
,10.3.0.0/16
) as the destination in the respective route tables.
๐ Step 7: Updating Security Groups to Allow All Traffic (For Testing Only)
To ensure temporary connectivity between EC2 instances across VPC-1, VPC-2, and VPC-3 during Transit Gateway testing, I updated the Security Groups (SGs) as follows:
Inbound Rules:
Type: All Traffic
Protocol: All
Port Range: All
Source:
0.0.0.0/0
or respective VPC CIDR blocks
Outbound Rules:
Type: All Traffic
Protocol: All
Port Range: All
Destination:
0.0.0.0/0
or respective VPC CIDR blocks
โ ๏ธ Note:
Allowing All Traffic (0.0.0.0/0) is not recommended for production environments.
This is done here only for understanding and testing purposes.
In real-world setups, always apply principle of least privilege for better security.
โ Final Step: Ping Test for Verification
Finally, I logged into EC2-1 (Public Server in VPC-1) and pinged the private IPs of EC2-2 (Private Server in VPC-2) and EC2-3 (Private Server in VPC-3).
The ping was successful, which confirms that communication between all VPCs is properly set up through the Transit Gateway.
๐ Note:
Allowing All Traffic in the Security Group was done only for testing and learning purposes.
This is not a recommended practice in production. Always apply least privilege security rules.
โ Final Wrap-Up: Transit Gateway Task
In this quick networking task, I configured 3 separate VPCs and successfully connected them using a single Transit Gateway.
Key highlights:
VPC-1 was made public via an Internet Gateway and a public subnet.
Proper route tables were updated in all VPCs to route traffic through the Transit Gateway.
Security Groups were temporarily set to allow all traffic for testing (โ ๏ธ Not recommended for production).
Finally, from the public EC2 in VPC-1, I was able to ping the private EC2 instances in VPC-2 and VPC-3.
โ๏ธ Result: Smooth inter-VPC communication confirmed via Transit Gateway setup.
๐จโ๐ป About the Author
This series isn't just about using AWS; it's about mastering the core services that power modern cloud infrastructure.
๐ฌ Let's Stay Connected
๐ง Email: gujjarapurv181@gmail.com
๐ GitHub: github.com/ApurvGujjar07
๐ผ LinkedIn: linkedin.com/in/apurv-gujjar
Subscribe to my newsletter
Read articles from Gujjar Apurv directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Gujjar Apurv
Gujjar Apurv
Gujjar Apurv is a passionate DevOps Engineer in the making, dedicated to automating infrastructure, streamlining software delivery, and building scalable cloud-native systems. With hands-on experience in tools like AWS, Docker, Kubernetes, Jenkins, Git, and Linux, he thrives at the intersection of development and operations. Driven by curiosity and continuous learning, Apurv shares insights, tutorials, and real-world solutions from his journeyโmaking complex tech simple and accessible. Whether it's writing YAML, scripting in Python, or deploying on the cloud, he believes in doing it the right way. "Infrastructure is code, but reliability is art."