Skip to content
v2.275.0

Experimental

@aws-cdk/aws-ec2-alpha is an experimental (alpha) package: its API may change in any release, without a major version bump.

RouteTargetType Class ​

The gateway or endpoint targeted by the route.

Example ​

ts
const stack = new Stack();
const myVpc = new VpcV2(this, 'Vpc');
const routeTable = new RouteTable(this, 'RouteTable', {
  vpc: myVpc,
});
const subnet = new SubnetV2(this, 'Subnet', {
  vpc: myVpc,
  availabilityZone: 'eu-west-2a',
  ipv4CidrBlock: new IpCidr('10.0.0.0/24'),
  subnetType: SubnetType.PRIVATE_ISOLATED });

const igw = new InternetGateway(this, 'IGW', {
  vpc: myVpc,
});
new Route(this, 'IgwRoute', {
  routeTable,
  destination: '0.0.0.0/0',
  target:  { gateway: igw },
});
python
stack = Stack()
my_vpc = VpcV2(self, "Vpc")
route_table = RouteTable(self, "RouteTable",
    vpc=my_vpc
)
subnet = SubnetV2(self, "Subnet",
    vpc=my_vpc,
    availability_zone="eu-west-2a",
    ipv4_cidr_block=IpCidr("10.0.0.0/24"),
    subnet_type=SubnetType.PRIVATE_ISOLATED
)

igw = InternetGateway(self, "IGW",
    vpc=my_vpc
)
Route(self, "IgwRoute",
    route_table=route_table,
    destination="0.0.0.0/0",
    target={"gateway": igw}
)
java
Stack stack = new Stack();
VpcV2 myVpc = new VpcV2(this, "Vpc");
RouteTable routeTable = RouteTable.Builder.create(this, "RouteTable")
        .vpc(myVpc)
        .build();
SubnetV2 subnet = SubnetV2.Builder.create(this, "Subnet")
        .vpc(myVpc)
        .availabilityZone("eu-west-2a")
        .ipv4CidrBlock(new IpCidr("10.0.0.0/24"))
        .subnetType(SubnetType.PRIVATE_ISOLATED)
        .build();

InternetGateway igw = InternetGateway.Builder.create(this, "IGW")
        .vpc(myVpc)
        .build();
Route.Builder.create(this, "IgwRoute")
        .routeTable(routeTable)
        .destination("0.0.0.0/0")
        .target(Map.of("gateway", igw))
        .build();
csharp
// Install: dotnet add package Amazon.CDK.AWS.ec2.Alpha
var stack = new Stack();
var myVpc = new VpcV2(this, "Vpc");
var routeTable = new RouteTable(this, "RouteTable", new RouteTableProps {
    Vpc = myVpc
});
var subnet = new SubnetV2(this, "Subnet", new SubnetV2Props {
    Vpc = myVpc,
    AvailabilityZone = "eu-west-2a",
    Ipv4CidrBlock = new IpCidr("10.0.0.0/24"),
    SubnetType = SubnetType.PRIVATE_ISOLATED
});

var igw = new InternetGateway(this, "IGW", new InternetGatewayProps {
    Vpc = myVpc
});
new Route(this, "IgwRoute", new RouteProps {
    RouteTable = routeTable,
    Destination = "0.0.0.0/0",
    Target = new Dictionary<string, IRouteTarget?> { { "gateway", igw } }
});
go
// Install: go get github.com/aws/aws-cdk-go/awsec2alpha/v2
stack := awscdk.Newstack()
myVpc := awsec2alpha.NewVpcV2(this, jsii.String("Vpc"))
routeTable := awsec2alpha.NewRouteTable(this, jsii.String("RouteTable"), &RouteTableProps{
	Vpc: myVpc,
})
subnet := awsec2alpha.NewSubnetV2(this, jsii.String("Subnet"), &SubnetV2Props{
	Vpc: myVpc,
	AvailabilityZone: jsii.String("eu-west-2a"),
	Ipv4CidrBlock: awsec2alpha.NewIpCidr(jsii.String("10.0.0.0/24")),
	SubnetType: awscdk.SubnetType_PRIVATE_ISOLATED,
})

igw := awsec2alpha.NewInternetGateway(this, jsii.String("IGW"), &InternetGatewayProps{
	Vpc: myVpc,
})
awsec2alpha.NewRoute(this, jsii.String("IgwRoute"), &RouteProps{
	RouteTable: RouteTable,
	Destination: jsii.String("0.0.0.0/0"),
	Target: map[string]iRouteTarget{
		"gateway": igw,
	},
})

Initializer ​

ts
new RouteTargetType(props: RouteTargetProps)
python
RouteTargetType(props: RouteTargetProps)
java
new RouteTargetType(RouteTargetProps props)
csharp
new RouteTargetType(RouteTargetProps props)
go
NewRouteTargetType(Props RouteTargetProps)

Properties ​

endpointmay be undefinedIVpcEndpointendpointmay be undefinedIVpcEndpointendpointmay be undefinedIVpcEndpointEndpointmay be undefinedIVpcEndpointEndpointmay be undefinedIVpcEndpoint#
The endpoint route target.

Default: target is not set to an endpoint, in this case a gateway is needed.

This is used for targets such as VPC endpoints.

gatewaymay be undefinedIRouteTargetgatewaymay be undefinedIRouteTargetgatewaymay be undefinedIRouteTargetGatewaymay be undefinedIRouteTargetGatewaymay be undefinedIRouteTarget#
The gateway route target.

Default: target is not set to a gateway, in this case an endpoint is needed.

This is used for targets such as egress-only internet gateway or VPC peering connection.