# PublicSubnetProps

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

- Source: [`aws-ec2/lib/vpc.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-ec2/lib/vpc.ts#L2592)

## 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';
import { aws_ec2 as interfaces_ec2 } from 'aws-cdk-lib/interfaces';

declare const iPAMPoolRef: interfaces_ec2.IIPAMPoolRef;
const publicSubnetProps: ec2.PublicSubnetProps = {
  availabilityZone: 'availabilityZone',
  vpcId: 'vpcId',

  // the properties below are optional
  assignIpv6AddressOnCreation: false,
  cidrBlock: 'cidrBlock',
  ipv4IpamAllocation: {
    ipamPool: iPAMPoolRef,
    netmaskLength: 123,
  },
  ipv6CidrBlock: 'ipv6CidrBlock',
  mapPublicIpOnLaunch: false,
};
```

Python:

```python
# 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
from aws_cdk.interfaces import aws_ec2 as interfaces_ec2

# i_pam_pool_ref: interfaces_ec2.IIPAMPoolRef

public_subnet_props = ec2.PublicSubnetProps(
    availability_zone="availabilityZone",
    vpc_id="vpcId",

    # the properties below are optional
    assign_ipv6_address_on_creation=False,
    cidr_block="cidrBlock",
    ipv4_ipam_allocation=ec2.SubnetIpv4IpamAllocation(
        ipam_pool=i_pam_pool_ref,
        netmask_length=123
    ),
    ipv6_cidr_block="ipv6CidrBlock",
    map_public_ip_on_launch=False
)
```

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.*;
import software.amazon.awscdk.interfaces.ec2.*;

IIPAMPoolRef iPAMPoolRef;

PublicSubnetProps publicSubnetProps = PublicSubnetProps.builder()
        .availabilityZone("availabilityZone")
        .vpcId("vpcId")

        // the properties below are optional
        .assignIpv6AddressOnCreation(false)
        .cidrBlock("cidrBlock")
        .ipv4IpamAllocation(SubnetIpv4IpamAllocation.builder()
                .ipamPool(iPAMPoolRef)
                .netmaskLength(123)
                .build())
        .ipv6CidrBlock("ipv6CidrBlock")
        .mapPublicIpOnLaunch(false)
        .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;
using Amazon.CDK.Interfaces.EC2;

IIPAMPoolRef iPAMPoolRef;

var publicSubnetProps = new PublicSubnetProps {
    AvailabilityZone = "availabilityZone",
    VpcId = "vpcId",

    // the properties below are optional
    AssignIpv6AddressOnCreation = false,
    CidrBlock = "cidrBlock",
    Ipv4IpamAllocation = new SubnetIpv4IpamAllocation {
        IpamPool = iPAMPoolRef,
        NetmaskLength = 123
    },
    Ipv6CidrBlock = "ipv6CidrBlock",
    MapPublicIpOnLaunch = false
};
```

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"
import "github.com/aws/aws-cdk-go/awscdk"

var iPAMPoolRef IIPAMPoolRef

publicSubnetProps := &PublicSubnetProps{
	AvailabilityZone: jsii.String("availabilityZone"),
	VpcId: jsii.String("vpcId"),

	// the properties below are optional
	AssignIpv6AddressOnCreation: jsii.Boolean(false),
	CidrBlock: jsii.String("cidrBlock"),
	Ipv4IpamAllocation: &SubnetIpv4IpamAllocation{
		IpamPool: iPAMPoolRef,
		NetmaskLength: jsii.Number(123),
	},
	Ipv6CidrBlock: jsii.String("ipv6CidrBlock"),
	MapPublicIpOnLaunch: jsii.Boolean(false),
}
```

## Properties

- `assignIpv6AddressOnCreation`: boolean = false — Indicates whether a network interface created in this subnet receives an IPv6 address.

  If you specify AssignIpv6AddressOnCreation, you must also specify Ipv6CidrBlock.

- `availabilityZone`: string (required) — The availability zone for the subnet.

- `cidrBlock`: string — The CIDR notation for this subnet.

  **Default:** the CIDR block is allocated from the IPAM pool given in `ipv4IpamAllocation`

  Exactly one of `cidrBlock` and `ipv4IpamAllocation` must be specified.

- `ipv4IpamAllocation`: [SubnetIpv4IpamAllocation](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.SubnetIpv4IpamAllocation.html) — Allocate the IPv4 CIDR block of this subnet from an IPAM pool at deploy time.

  **Default:** the subnet uses the concrete `cidrBlock`

  When set, `ipv4CidrBlock` resolves to a deploy-time attribute of the subnet instead of a
  concrete string, so `SubnetFilter.byCidrMask()`, `SubnetFilter.byCidrRanges()` and
  `SubnetFilter.containsIpAddresses()` cannot be used with this subnet.

  Exactly one of `cidrBlock` and `ipv4IpamAllocation` must be specified.

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

  **Default:** no IPv6 CIDR block.

  If you specify AssignIpv6AddressOnCreation, you must also specify Ipv6CidrBlock.

- `mapPublicIpOnLaunch`: boolean — Controls if a public IP is associated to an instance at launch.

  **Default:** true in Subnet.Public, false in Subnet.Private or Subnet.Isolated.

- `vpcId`: string (required) — The VPC which this subnet is part of.
