Skip to content
v2.277.0

AddRouteOptions Struct ​

Options for adding a new route to a subnet.

Example ​

ts
const vpc = new ec2.Vpc(this, "VPC", {
  subnetConfiguration: [{
      subnetType: ec2.SubnetType.PUBLIC,
      name: 'Public',
    },{
      subnetType: ec2.SubnetType.PRIVATE_ISOLATED,
      name: 'Isolated',
    }]
});

(vpc.isolatedSubnets[0] as ec2.Subnet).addRoute("StaticRoute", {
    routerId: vpc.internetGatewayId!,
    routerType: ec2.RouterType.GATEWAY,
    destinationCidrBlock: "8.8.8.8/32",
})
python
vpc = ec2.Vpc(self, "VPC",
    subnet_configuration=[ec2.SubnetConfiguration(
        subnet_type=ec2.SubnetType.PUBLIC,
        name="Public"
    ), ec2.SubnetConfiguration(
        subnet_type=ec2.SubnetType.PRIVATE_ISOLATED,
        name="Isolated"
    )]
)

(vpc.isolated_subnets[0]).add_route("StaticRoute",
    router_id=vpc.internet_gateway_id,
    router_type=ec2.RouterType.GATEWAY,
    destination_cidr_block="8.8.8.8/32"
)
java
Vpc vpc = Vpc.Builder.create(this, "VPC")
        .subnetConfiguration(List.of(SubnetConfiguration.builder()
                .subnetType(SubnetType.PUBLIC)
                .name("Public")
                .build(), SubnetConfiguration.builder()
                .subnetType(SubnetType.PRIVATE_ISOLATED)
                .name("Isolated")
                .build()))
        .build();

((Subnet)vpc.isolatedSubnets[0]).addRoute("StaticRoute", AddRouteOptions.builder()
        .routerId(vpc.getInternetGatewayId())
        .routerType(RouterType.GATEWAY)
        .destinationCidrBlock("8.8.8.8/32")
        .build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
var vpc = new Vpc(this, "VPC", new VpcProps {
    SubnetConfiguration = new [] { new SubnetConfiguration {
        SubnetType = SubnetType.PUBLIC,
        Name = "Public"
    }, new SubnetConfiguration {
        SubnetType = SubnetType.PRIVATE_ISOLATED,
        Name = "Isolated"
    } }
});

((Subnet)vpc.IsolatedSubnets[0]).AddRoute("StaticRoute", new AddRouteOptions {
    RouterId = vpc.InternetGatewayId,
    RouterType = RouterType.GATEWAY,
    DestinationCidrBlock = "8.8.8.8/32"
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
vpc := ec2.NewVpc(this, jsii.String("VPC"), &VpcProps{
	SubnetConfiguration: []SubnetConfiguration{
		&SubnetConfiguration{
			SubnetType: ec2.SubnetType_PUBLIC,
			Name: jsii.String("Public"),
		},
		&SubnetConfiguration{
			SubnetType: ec2.SubnetType_PRIVATE_ISOLATED,
			Name: jsii.String("Isolated"),
		},
	},
})

(vpc.IsolatedSubnets[0].(Subnet)).AddRoute(jsii.String("StaticRoute"), &AddRouteOptions{
	RouterId: vpc.InternetGatewayId,
	RouterType: ec2.RouterType_GATEWAY,
	DestinationCidrBlock: jsii.String("8.8.8.8/32"),
})

Properties ​

destinationCidrBlockoptionalstringdestination_cidr_blockoptionalstrdestinationCidrBlockoptionalStringDestinationCidrBlockoptionalstringDestinationCidrBlockoptional*string = '0.0.0.0/0' #
IPv4 range this route applies to.
destinationIpv6CidrBlockoptionalstringdestination_ipv6_cidr_blockoptionalstrdestinationIpv6CidrBlockoptionalStringDestinationIpv6CidrBlockoptionalstringDestinationIpv6CidrBlockoptional*string #
IPv6 range this route applies to.

Default: Uses IPv6

enablesInternetConnectivityoptionalbooleanenables_internet_connectivityoptionalboolenablesInternetConnectivityoptionalBooleanEnablesInternetConnectivityoptionalboolEnablesInternetConnectivityoptional*bool = false #
Whether this route will enable internet connectivity.

If true, this route will be added before any AWS resources that depend on internet connectivity in the VPC will be created.

routerIdstringrouter_idstrrouterIdStringRouterIdstringRouterId*string required #
The ID of the router.

Can be an instance ID, gateway ID, etc, depending on the router type.

routerTypeRouterTyperouter_typeRouterTyperouterTypeRouterTypeRouterTypeRouterTypeRouterTypeRouterType required #
What type of router to route this traffic to.