Creating and Connecting AWS VPCs with Transit Gateway — Access via MobaXterm on Windows

saumya singhsaumya singh
3 min read

Introduction

In modern cloud architectures, it's common to have multiple Virtual Private Clouds (VPCs) for isolation, security, and scaling purposes. But what if your workloads in different VPCs need to communicate securely and efficiently?
That’s where AWS Transit Gateway comes in — acting as a central hub to connect your VPCs, on-premises networks, and more.

In this tutorial, we’ll:

  • Create multiple VPCs in AWS.

  • Connect them using a Transit Gateway.

  • Access EC2 instances from Windows using MobaXterm for SSH connectivity.


Architecture Diagram

Below is the high-level architecture:

         +-------------------+             +-------------------+
         |    VPC 1 (Public) |             |    VPC 2 (Private) |
         |  EC2 Instance A   |             |  EC2 Instance B   |
         +--------+----------+             +--------+----------+
                  \                              /
                   \                            /
                    +-------- Transit ---------+
                    |        Gateway           |
                    +--------------------------+
                             |
                             |
                        AWS Backbone

Step 1: Create VPCs

  1. Login to AWS Management Console → Go to VPC service.

  2. Create VPC 1 (Public subnet)

    • CIDR Block: 10.0.0.0/16

    • Create a Public Subnet: 10.0.1.0/24

    • Enable Auto-assign Public IP.

  3. Create VPC 2 (Private subnet)

    • CIDR Block: 10.1.0.0/16

    • Create a Private Subnet: 10.1.1.0/24


Step 2: Launch EC2 Instances

  • In VPC 1 (Public) → Launch an Amazon Linux or Ubuntu instance. Assign a public IP.

  • In VPC 2 (Private) → Launch an instance without a public IP (we’ll reach it via VPC connectivity).


Step 3: Create a Transit Gateway

  1. Navigate to Transit Gateway in AWS Console.

  2. Click Create Transit Gateway:

    • Name: TGW-Demo

    • Amazon ASN: Keep default (e.g., 64512).

  3. Once created, note the Transit Gateway ID.


Step 4: Attach VPCs to Transit Gateway

  • Go to Transit Gateway AttachmentsCreate attachment.

  • Select VPC 1 and attach it to TGW.

  • Repeat for VPC 2.


Step 5: Update Route Tables

  • For VPC 1 Route Table → Add a route for 10.1.0.0/16 pointing to Transit Gateway.

  • For VPC 2 Route Table → Add a route for 10.0.0.0/16 pointing to Transit Gateway.


Step 6: Access EC2 Instances from Windows (MobaXterm)

Install MobaXterm:

Connect to VPC 1 EC2 Instance:

  1. Open MobaXterm → Click Session → SSH.

  2. Enter Public IP of VPC 1 EC2.

  3. Browse and select your .pem key in Advanced SSH settings.

Access VPC 2 EC2 via VPC 1:

  • First SSH into VPC 1 EC2.

  • From there, run:

      ssh -i "key.pem" ec2-user@<Private-IP-of-VPC2-EC2>
    

Conclusion

With AWS Transit Gateway, we’ve connected two VPCs to enable secure communication without complex peering configurations. By using MobaXterm, we easily accessed the EC2 instances from our Windows machine — even those in private subnets.


Learning Outcomes

  • Understand how Transit Gateway acts as a central networking hub.

  • Configure route tables for inter-VPC communication.

  • Use MobaXterm for SSH access to EC2 instances across VPCs.


11
Subscribe to my newsletter

Read articles from saumya singh directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

saumya singh
saumya singh

Welcome to my corner of the cloud, where ideas scale faster than servers and downtime is not an option! Here, I write about everything from spinning up VPCs to tearing down myths about the cloud. Whether you’re an engineer, a curious learner, or someone who just likes seeing words like 'serverless' and 'auto-scaling,' you’re in the right place. Consider this blog your high-availability zone for tips, tutorials, and tech thoughts—delivered with 99.99% uptime .