Skip to content
GitHubXDiscord

TransitGatewayRoute

The TransitGatewayRoute resource allows you to manage AWS EC2 Transit Gateway Routes. This resource is essential for controlling the routing of traffic between multiple VPCs and on-premises networks via a Transit Gateway.

Create a basic Transit Gateway Route with required properties.

import AWS from "alchemy/aws/control";
const transitGatewayRoute = await AWS.EC2.TransitGatewayRoute("basicRoute", {
TransitGatewayRouteTableId: "tgw-rtb-0a1b2c3d4e5f6g7h8",
DestinationCidrBlock: "10.0.0.0/16",
TransitGatewayAttachmentId: "tgw-attach-0a1b2c3d4e5f6g7h8", // Optional but common
Blackhole: false // Default false: Route is active
});

Configure a Transit Gateway Route with additional options such as enabling blackhole routing.

const advancedRoute = await AWS.EC2.TransitGatewayRoute("advancedRoute", {
TransitGatewayRouteTableId: "tgw-rtb-0a1b2c3d4e5f6g7h8",
DestinationCidrBlock: "192.168.1.0/24",
Blackhole: true, // Enable blackhole routing for traffic
TransitGatewayAttachmentId: "tgw-attach-0a1b2c3d4e5f6g7h8"
});

If you want to adopt an existing Transit Gateway Route instead of creating a new one, use the adopt property.

const adoptedRoute = await AWS.EC2.TransitGatewayRoute("adoptedRoute", {
TransitGatewayRouteTableId: "tgw-rtb-0a1b2c3d4e5f6g7h8",
DestinationCidrBlock: "172.16.0.0/12",
adopt: true // Enable adoption of existing resource
});

Create a route to interconnect two VPCs through a Transit Gateway.

const interconnectRoute = await AWS.EC2.TransitGatewayRoute("interconnectRoute", {
TransitGatewayRouteTableId: "tgw-rtb-0a1b2c3d4e5f6g7h8",
DestinationCidrBlock: "10.1.0.0/16",
TransitGatewayAttachmentId: "tgw-attach-0a1b2c3d4e5f6g7h8"
});