Experimental
@aws-cdk/aws-ec2-alpha is an experimental (alpha) package: its API may change in any release, without a major version bump.
AttachVpcOptions Struct
Options for creating an Attachment via the attachVpc() method.
| Stability | Experimental |
|---|---|
| Source | lib/transit-gateway-vpc-attachment.ts |
Example
ts
const transitGateway = new TransitGateway(this, 'MyTransitGateway');
const routeTable = transitGateway.addRouteTable('CustomRouteTable');
const myVpc = new VpcV2(this, 'Vpc');
const subnet = new SubnetV2(this, 'Subnet', {
vpc: myVpc,
availabilityZone: 'eu-west-2a',
ipv4CidrBlock: new IpCidr('10.0.0.0/24'),
subnetType: SubnetType.PUBLIC
});
const attachment = transitGateway.attachVpc('VpcAttachment', {
vpc: myVpc,
subnets: [subnet]
});
// Add a static route to direct traffic
routeTable.addRoute('StaticRoute', attachment, '10.0.0.0/16');
// Block unwanted traffic with a blackhole route
routeTable.addBlackholeRoute('BlackholeRoute', '172.16.0.0/16');
python
transit_gateway = TransitGateway(self, "MyTransitGateway")
route_table = transit_gateway.add_route_table("CustomRouteTable")
my_vpc = VpcV2(self, "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.PUBLIC
)
attachment = transit_gateway.attach_vpc("VpcAttachment",
vpc=my_vpc,
subnets=[subnet]
)
# Add a static route to direct traffic
route_table.add_route("StaticRoute", attachment, "10.0.0.0/16")
# Block unwanted traffic with a blackhole route
route_table.add_blackhole_route("BlackholeRoute", "172.16.0.0/16")
java
TransitGateway transitGateway = new TransitGateway(this, "MyTransitGateway");
ITransitGatewayRouteTable routeTable = transitGateway.addRouteTable("CustomRouteTable");
VpcV2 myVpc = new VpcV2(this, "Vpc");
SubnetV2 subnet = SubnetV2.Builder.create(this, "Subnet")
.vpc(myVpc)
.availabilityZone("eu-west-2a")
.ipv4CidrBlock(new IpCidr("10.0.0.0/24"))
.subnetType(SubnetType.PUBLIC)
.build();
ITransitGatewayVpcAttachment attachment = transitGateway.attachVpc("VpcAttachment", AttachVpcOptions.builder()
.vpc(myVpc)
.subnets(List.of(subnet))
.build());
// Add a static route to direct traffic
routeTable.addRoute("StaticRoute", attachment, "10.0.0.0/16");
// Block unwanted traffic with a blackhole route
routeTable.addBlackholeRoute("BlackholeRoute", "172.16.0.0/16");
csharp
// Install: dotnet add package Amazon.CDK.AWS.ec2.Alpha
var transitGateway = new TransitGateway(this, "MyTransitGateway");
var routeTable = transitGateway.AddRouteTable("CustomRouteTable");
var myVpc = new VpcV2(this, "Vpc");
var subnet = new SubnetV2(this, "Subnet", new SubnetV2Props {
Vpc = myVpc,
AvailabilityZone = "eu-west-2a",
Ipv4CidrBlock = new IpCidr("10.0.0.0/24"),
SubnetType = SubnetType.PUBLIC
});
var attachment = transitGateway.AttachVpc("VpcAttachment", new AttachVpcOptions {
Vpc = myVpc,
Subnets = new [] { subnet }
});
// Add a static route to direct traffic
routeTable.AddRoute("StaticRoute", attachment, "10.0.0.0/16");
// Block unwanted traffic with a blackhole route
routeTable.AddBlackholeRoute("BlackholeRoute", "172.16.0.0/16");
go
// Install: go get github.com/aws/aws-cdk-go/awsec2alpha/v2
transitGateway := awsec2alpha.NewTransitGateway(this, jsii.String("MyTransitGateway"))
routeTable := transitGateway.addRouteTable(jsii.String("CustomRouteTable"))
myVpc := awsec2alpha.NewVpcV2(this, jsii.String("Vpc"))
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_PUBLIC,
})
attachment := transitGateway.attachVpc(jsii.String("VpcAttachment"), &AttachVpcOptions{
Vpc: myVpc,
Subnets: []ISubnet{
subnet,
},
})
// Add a static route to direct traffic
routeTable.AddRoute(jsii.String("StaticRoute"), attachment, jsii.String("10.0.0.0/16"))
// Block unwanted traffic with a blackhole route
routeTable.AddBlackholeRoute(jsii.String("BlackholeRoute"), jsii.String("172.16.0.0/16"))
Properties
associationRouteTableoptionalITransitGatewayRouteTableassociation_route_tableoptionalITransitGatewayRouteTableassociationRouteTableoptionalITransitGatewayRouteTableAssociationRouteTableoptionalITransitGatewayRouteTableAssociationRouteTableoptionalITransitGatewayRouteTable #An optional route table to associate with this VPC attachment.
Default: No associations will be created unless it is for the default route table and automatic association is enabled.
propagationRouteTablesoptionalITransitGatewayRouteTable[]propagation_route_tablesoptionaltyping.List[ITransitGatewayRouteTable]propagationRouteTablesoptionalList<ITransitGatewayRouteTable>PropagationRouteTablesoptionalITransitGatewayRouteTable[]PropagationRouteTablesoptional*[]ITransitGatewayRouteTable #A list of optional route tables to propagate routes to.
Default: No propagations will be created unless it is for the default route table and automatic propagation is enabled.
subnetsISubnet[]subnetstyping.List[ISubnet]subnetsList<ISubnet>SubnetsISubnet[]Subnets*[]ISubnet required #A list of one or more subnets to place the attachment in.
It is recommended to specify more subnets for better availability.
transitGatewayAttachmentNameoptionalstringtransit_gateway_attachment_nameoptionalstrtransitGatewayAttachmentNameoptionalStringTransitGatewayAttachmentNameoptionalstringTransitGatewayAttachmentNameoptional*string #Physical name of this Transit Gateway VPC Attachment.
Default: Assigned by CloudFormation.
vpcAttachmentOptionsoptionalITransitGatewayVpcAttachmentOptionsvpc_attachment_optionsoptionalITransitGatewayVpcAttachmentOptionsvpcAttachmentOptionsoptionalITransitGatewayVpcAttachmentOptionsVpcAttachmentOptionsoptionalITransitGatewayVpcAttachmentOptionsVpcAttachmentOptionsoptionalITransitGatewayVpcAttachmentOptions #The VPC attachment options.
Default: All options are disabled.