# CfnSubnetProps

Properties for defining a `CfnSubnet`.

Used as props by: [CfnSubnet](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnSubnet.html)

- Source: Generated at build time
- Type last changed: v2.227.0 · 21 Nov 2025

## Example

TypeScript:

```ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { aws_ec2 as ec2 } from 'aws-cdk-lib';

declare const privateDnsNameOptionsOnLaunch: any;
const cfnSubnetProps: ec2.CfnSubnetProps = {
  vpcId: 'vpcId',

  // the properties below are optional
  assignIpv6AddressOnCreation: false,
  availabilityZone: 'availabilityZone',
  availabilityZoneId: 'availabilityZoneId',
  cidrBlock: 'cidrBlock',
  enableDns64: false,
  enableLniAtDeviceIndex: 123,
  ipv4IpamPoolId: 'ipv4IpamPoolId',
  ipv4NetmaskLength: 123,
  ipv6CidrBlock: 'ipv6CidrBlock',
  ipv6IpamPoolId: 'ipv6IpamPoolId',
  ipv6Native: false,
  ipv6NetmaskLength: 123,
  mapPublicIpOnLaunch: false,
  outpostArn: 'outpostArn',
  privateDnsNameOptionsOnLaunch: privateDnsNameOptionsOnLaunch,
  tags: [{
    key: 'key',
    value: 'value',
  }],
};
```

Python:

```python
from aws_cdk import CfnTag
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
from aws_cdk import aws_ec2 as ec2

# private_dns_name_options_on_launch: Any

cfn_subnet_props = ec2.CfnSubnetProps(
    vpc_id="vpcId",

    # the properties below are optional
    assign_ipv6_address_on_creation=False,
    availability_zone="availabilityZone",
    availability_zone_id="availabilityZoneId",
    cidr_block="cidrBlock",
    enable_dns64=False,
    enable_lni_at_device_index=123,
    ipv4_ipam_pool_id="ipv4IpamPoolId",
    ipv4_netmask_length=123,
    ipv6_cidr_block="ipv6CidrBlock",
    ipv6_ipam_pool_id="ipv6IpamPoolId",
    ipv6_native=False,
    ipv6_netmask_length=123,
    map_public_ip_on_launch=False,
    outpost_arn="outpostArn",
    private_dns_name_options_on_launch=private_dns_name_options_on_launch,
    tags=[CfnTag(
        key="key",
        value="value"
    )]
)
```

Java:

```java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.services.ec2.*;

Object privateDnsNameOptionsOnLaunch;

CfnSubnetProps cfnSubnetProps = CfnSubnetProps.builder()
        .vpcId("vpcId")

        // the properties below are optional
        .assignIpv6AddressOnCreation(false)
        .availabilityZone("availabilityZone")
        .availabilityZoneId("availabilityZoneId")
        .cidrBlock("cidrBlock")
        .enableDns64(false)
        .enableLniAtDeviceIndex(123)
        .ipv4IpamPoolId("ipv4IpamPoolId")
        .ipv4NetmaskLength(123)
        .ipv6CidrBlock("ipv6CidrBlock")
        .ipv6IpamPoolId("ipv6IpamPoolId")
        .ipv6Native(false)
        .ipv6NetmaskLength(123)
        .mapPublicIpOnLaunch(false)
        .outpostArn("outpostArn")
        .privateDnsNameOptionsOnLaunch(privateDnsNameOptionsOnLaunch)
        .tags(List.of(CfnTag.builder()
                .key("key")
                .value("value")
                .build()))
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK.AWS.EC2;

var privateDnsNameOptionsOnLaunch;

var cfnSubnetProps = new CfnSubnetProps {
    VpcId = "vpcId",

    // the properties below are optional
    AssignIpv6AddressOnCreation = false,
    AvailabilityZone = "availabilityZone",
    AvailabilityZoneId = "availabilityZoneId",
    CidrBlock = "cidrBlock",
    EnableDns64 = false,
    EnableLniAtDeviceIndex = 123,
    Ipv4IpamPoolId = "ipv4IpamPoolId",
    Ipv4NetmaskLength = 123,
    Ipv6CidrBlock = "ipv6CidrBlock",
    Ipv6IpamPoolId = "ipv6IpamPoolId",
    Ipv6Native = false,
    Ipv6NetmaskLength = 123,
    MapPublicIpOnLaunch = false,
    OutpostArn = "outpostArn",
    PrivateDnsNameOptionsOnLaunch = privateDnsNameOptionsOnLaunch,
    Tags = new [] { new CfnTag {
        Key = "key",
        Value = "value"
    } }
};
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"

var privateDnsNameOptionsOnLaunch interface{}

cfnSubnetProps := &CfnSubnetProps{
	VpcId: jsii.String("vpcId"),

	// the properties below are optional
	AssignIpv6AddressOnCreation: jsii.Boolean(false),
	AvailabilityZone: jsii.String("availabilityZone"),
	AvailabilityZoneId: jsii.String("availabilityZoneId"),
	CidrBlock: jsii.String("cidrBlock"),
	EnableDns64: jsii.Boolean(false),
	EnableLniAtDeviceIndex: jsii.Number(123),
	Ipv4IpamPoolId: jsii.String("ipv4IpamPoolId"),
	Ipv4NetmaskLength: jsii.Number(123),
	Ipv6CidrBlock: jsii.String("ipv6CidrBlock"),
	Ipv6IpamPoolId: jsii.String("ipv6IpamPoolId"),
	Ipv6Native: jsii.Boolean(false),
	Ipv6NetmaskLength: jsii.Number(123),
	MapPublicIpOnLaunch: jsii.Boolean(false),
	OutpostArn: jsii.String("outpostArn"),
	PrivateDnsNameOptionsOnLaunch: privateDnsNameOptionsOnLaunch,
	Tags: []CfnTag{
		&CfnTag{
			Key: jsii.String("key"),
			Value: jsii.String("value"),
		},
	},
}
```

## Properties

- `assignIpv6AddressOnCreation`: boolean | [IResolvable](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) — Indicates whether a network interface created in this subnet receives an IPv6 address. The default value is `false` .

  If you specify `AssignIpv6AddressOnCreation` , you must also specify an IPv6 CIDR block.

- `availabilityZone`: string — The Availability Zone of the subnet.

  If you update this property, you must also update the `CidrBlock` property.

- `availabilityZoneId`: string — The AZ ID of the subnet.

- `cidrBlock`: string — The IPv4 CIDR block assigned to the subnet.

  If you update this property, we create a new subnet, and then delete the existing one.

- `enableDns64`: boolean | [IResolvable](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) — Indicates whether DNS queries made to the Amazon-provided DNS Resolver in this subnet should return synthetic IPv6 addresses for IPv4-only destinations.

  > You must first configure a NAT gateway in a public subnet (separate from the subnet containing the IPv6-only workloads). For example, the subnet containing the NAT gateway should have a `0.0.0.0/0` route pointing to the internet gateway. For more information, see [Configure DNS64 and NAT64](https://docs.aws.amazon.com/vpc/latest/userguide/nat-gateway-nat64-dns64.html#nat-gateway-nat64-dns64-walkthrough) in the *Amazon Virtual Private Cloud User Guide* .

- `enableLniAtDeviceIndex`: number — Indicates the device position for local network interfaces in this subnet.

  For example, `1` indicates local network interfaces in this subnet are the secondary network interface (eth1).

- `ipv4IpamPoolId`: string — An IPv4 IPAM pool ID for the subnet.

- `ipv4NetmaskLength`: number — An IPv4 netmask length for the subnet.

- `ipv6CidrBlock`: string — The IPv6 CIDR block.

  If you specify `AssignIpv6AddressOnCreation` , you must also specify an IPv6 CIDR block.

- `ipv6IpamPoolId`: string — An IPv6 IPAM pool ID for the subnet.

- `ipv6Native`: boolean | [IResolvable](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) — Indicates whether this is an IPv6 only subnet.

  For more information, see [Subnet basics](https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Subnets.html#subnet-basics) in the *Amazon Virtual Private Cloud User Guide* .

- `ipv6NetmaskLength`: number — An IPv6 netmask length for the subnet.

- `mapPublicIpOnLaunch`: boolean | [IResolvable](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) — Indicates whether instances launched in this subnet receive a public IPv4 address. The default value is `false` .

  AWS charges for all public IPv4 addresses, including public IPv4 addresses associated with running instances and Elastic IP addresses. For more information, see the *Public IPv4 Address* tab on the [VPC pricing page](https://docs.aws.amazon.com/vpc/pricing/) .

- `outpostArn`: string — The Amazon Resource Name (ARN) of the Outpost.

- `privateDnsNameOptionsOnLaunch`: any — The hostname type for EC2 instances launched into this subnet and how DNS A and AAAA record queries to the instances should be handled.

  For more information, see [Amazon EC2 instance hostname types](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-naming.html) in the *Amazon Elastic Compute Cloud User Guide* .

  Available options:

  - EnableResourceNameDnsAAAARecord (true | false)
  - EnableResourceNameDnsARecord (true | false)
  - HostnameType (ip-name | resource-name)

- `tags`: [CfnTag](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.CfnTag.html)[] — Any tags assigned to the subnet.

- `vpcId`: string | [IVPCRef](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_ec2.IVPCRef.html) (required) — The ID of the VPC the subnet is in.

  If you update this property, you must also update the `CidrBlock` property.
