How to Control AWS Transit Gateway Traffic with VRF

In the AWS centralized transit gateway, traffic is routed among VPCs using the transit gateway default route table. In this scenario, you get full mesh connectivity between all those networking components. But in this case, what’s happening is that now from any VPC, we can reach any other VPC, like from VPC A, I could reach B or C and the other way around.

But maybe in certain scenarios, you don’t want VPC A and VPC C to communicate with each other. To prevent this, you can assign each VPC attachment to the transit gateway to a specific VRF (virtual routing & forwarding). Each VRF has its own customizable route table that controls which other attachments the VPC can reach through the transit gateway.

So you can configure the route tables so that VPC A and VPC C are isolated from each other, while still allowing other VPCs attached to the transit gateway to communicate as needed. Using VRFs provides more granular control over connectivity between VPCs compared to using a single default route table.

Let’s walk through a step-by-step example of how to do this.

Architecture diagram for our use case
Architecture diagram for our use case

Here in this scenario, we want the communication to happen between VPC A to B and also B to C but not between A to C. We will walk through this diagram and learn how to configure it step by step. 

Step 1: Initial Setup

Before diving into the intricacies of AWS Transit Gateway, ensure you have the following prerequisites in place:

Three VPCs set up in your AWS account: VPC A, VPC B, and VPC C. VPC A with at least 2 subnets, one private and another public.

List of VPCs

VPC A should also have a jump host and an internet gateway to facilitate remote access. 

List of private EC2 instances with jump host

From the Jump Host, you should be able to ssh to the private instance in that same VPC. i.e VPC A.

Accessing private instances from the jump host

Each VPC should contain at least one EC2 instance in the private subnet.

Here is one jump host in a public subnet and 3 private instances in 3 private subnets. 

Here is one jump host in a public subnet and 3 private instances in 3 private subnets. 

Ensure you allow ping in the security group of private instances from all sources. 

Step 2: Create a Transit Gateway

Let’s start by creating the Transit Gateway that will serve as the central hub for our network connectivity:

From the AWS Management Console, navigate to the “Services” menu. 

Select “VPC,” and click on “Transit Gateway from the left sidebar.

Click the “Create Transit Gateway” button.

Creating transit gateway

Give the name to the Transit Gateway. Provide the description.

Disable both default route propagation and default route table association.

Configuring transit gateway details

Leave other things as default and click on “Create transit gateway.” 

Wait for a couple of minutes until the state is changed to “Available.”

Transit Gateway was created successfully

Step 3: Creating Transit Gateway Attachments

Attachments are the links between your VPCs and the Transit Gateway. 

Go to “Transit gateway attachment.”

Click “Create Transit Gateway Attachment.”

Creating transit gateway attachment

Give the name to the transit gateway attachment.

Select the Transit Gateway you just created.

Select the attachment type as “VPC.”