# SubnetMapping

Specifies a subnet for a load balancer.

- Source: [`aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts#L57)
- Type last changed: v2.190.0 · 17 Apr 2025

## Example

```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_elasticloadbalancingv2 as elbv2 } from 'aws-cdk-lib';

declare const sourceNatIpv6Prefix: elbv2.SourceNatIpv6Prefix;
declare const subnet: ec2.Subnet;
const subnetMapping: elbv2.SubnetMapping = {
  subnet: subnet,

  // the properties below are optional
  allocationId: 'allocationId',
  ipv6Address: 'ipv6Address',
  privateIpv4Address: 'privateIpv4Address',
  sourceNatIpv6Prefix: sourceNatIpv6Prefix,
};
```

## Properties

- `allocationId`: string — The allocation ID of the Elastic IP address for an internet-facing load balancer.

  **Default:** undefined - AWS default is to allocate a new IP address for internet-facing load balancers

- `ipv6Address`: string — The IPv6 address.

  **Default:** undefined - AWS default is to allocate an IPv6 address from the subnet's pool

- `privateIpv4Address`: string — The private IPv4 address for an internal load balancer.

  **Default:** undefined - AWS default is to allocate a private IPv4 address from the subnet's pool

- `sourceNatIpv6Prefix`: [SourceNatIpv6Prefix](/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancingv2.SourceNatIpv6Prefix.html) — The IPv6 prefix to use for source NAT for a dual-stack network load balancer with UDP listeners.

  **Default:** undefined - AWS default is `SourceNatIpv6Prefix.autoAssigned()` for IPv6 load balancers

  Specify an IPv6 prefix (/80 netmask) from the subnet CIDR block
  or `SourceNatIpv6Prefix.autoAssigned()` to use an IPv6 prefix selected at random from the subnet CIDR block.

- `subnet`: [ISubnet](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.ISubnet.html) (required) — The subnet.
