Skip to content
v2.273.0

Experimental

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

SubnetV2Props Struct ​

Properties to define subnet for VPC.

Example ​

ts
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 natgw = new NatGateway(this, 'NatGW', {
  subnet: subnet,
  vpc: myVpc,
  connectivityType: NatConnectivityType.PRIVATE,
  privateIpAddress: '10.0.0.42',
});
new Route(this, 'NatGwRoute', {
  routeTable,
  destination: '0.0.0.0/0',
  target: { gateway: natgw },
});

Properties ​

assignIpv6AddressOnCreationbooleanassign_ipv6_address_on_creationboolassignIpv6AddressOnCreationBooleanAssignIpv6AddressOnCreationboolAssignIpv6AddressOnCreation*bool= undefined in case not provided a…#
Indicates whether a network interface created in this subnet receives an IPv6 address.

If you specify AssignIpv6AddressOnCreation, you must also specify Ipv6CidrBlock.

default

Default: undefined in case not provided as an input

availabilityZonestringavailability_zonestravailabilityZoneStringAvailabilityZonestringAvailabilityZone*stringrequired#
Custom AZ for the subnet.
defaultRouteTableNamestringdefault_route_table_namestrdefaultRouteTableNameStringDefaultRouteTableNamestringDefaultRouteTableName*string= default route table name created…#
Name of the default RouteTable created by CDK to be used for tagging.
default

Default: default route table name created by CDK as 'DefaultCDKRouteTable'

ipv4CidrBlockIpCidripv4_cidr_blockIpCidripv4CidrBlockIpCidrIpv4CidrBlockIpCidrIpv4CidrBlockIpCidrrequired#
ipv4 cidr to assign to this subnet.
ipv6CidrBlockIpCidripv6_cidr_blockIpCidripv6CidrBlockIpCidrIpv6CidrBlockIpCidrIpv6CidrBlockIpCidr= No Ipv6 address#
Ipv6 CIDR Range for subnet.
mapPublicIpOnLaunchbooleanmap_public_ip_on_launchboolmapPublicIpOnLaunchBooleanMapPublicIpOnLaunchboolMapPublicIpOnLaunch*bool= undefined in case not provided a…#
Controls if instances launched into the subnet should be assigned a public IP address.

This property can only be set for public subnets.

default

Default: undefined in case not provided as an input

routeTableIRouteTableroute_tableIRouteTablerouteTableIRouteTableRouteTableIRouteTableRouteTableIRouteTable= a default route table created#
Custom Route for subnet.
subnetNamestringsubnet_namestrsubnetNameStringSubnetNamestringSubnetName*string= provisioned with an autogenerate…#
Subnet name.
default

Default: provisioned with an autogenerated name by CDK

subnetTypeSubnetTypesubnet_typeSubnetTypesubnetTypeSubnetTypeSubnetTypeSubnetTypeSubnetTypeSubnetTyperequired#
The type of Subnet to configure.

The Subnet type will control the ability to route and connect to the Internet.

TODO: Add validation check subnetType when adding resources (e.g. cannot add NatGateway to private)

vpcIVpcV2vpcIVpcV2vpcIVpcV2VpcIVpcV2VpcIVpcV2required#
VPC Prop.

Used as props by ​