Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/@aws-cdk/aws-ec2-alpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ new VpcV2(this, 'Vpc', {
`SubnetV2` is a re-write of the [`ec2.Subnet`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.Subnet.html) construct.
This new construct can be used to add subnets to a `VpcV2` instance:
Note: When defining a subnet with `SubnetV2`, CDK automatically creates a new route table, unless a route table is explicitly provided as an input to the construct.
To enable the `mapPublicIpOnLaunch` feature (which is `false` by default), set the property to `true` when creating the subnet.

```ts
const stack = new Stack();
Expand All @@ -57,7 +58,8 @@ new SubnetV2(this, 'subnetA', {
availabilityZone: 'us-east-1a',
ipv4CidrBlock: new IpCidr('10.0.0.0/24'),
ipv6CidrBlock: new IpCidr('2a05:d02c:25:4000::/60'),
subnetType: SubnetType.PRIVATE_ISOLATED,
subnetType: SubnetType.PUBLIC,
mapPublicIpOnLaunch: true,
})
```

Expand Down
13 changes: 13 additions & 0 deletions packages/@aws-cdk/aws-ec2-alpha/lib/subnet-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ export interface SubnetV2Props {
*/
readonly assignIpv6AddressOnCreation?: boolean;

/**
* Controls if instances launched into the subnet should be assigned a public IP address.
* This property can only be set for public subnets.
*
* @default - undefined in case not provided as an input
*/
readonly mapPublicIpOnLaunch?: boolean;

}

/**
Expand Down Expand Up @@ -276,12 +284,17 @@ export class SubnetV2 extends Resource implements ISubnetV2 {
throw new Error('IPv6 CIDR block is required when assigning IPv6 address on creation');
}

if (props.mapPublicIpOnLaunch === true && props.subnetType !== SubnetType.PUBLIC) {
throw new Error('mapPublicIpOnLaunch can only be set to true for public subnets');
}

const subnet = new CfnSubnet(this, 'Subnet', {
vpcId: props.vpc.vpcId,
cidrBlock: ipv4CidrBlock,
ipv6CidrBlock: ipv6CidrBlock,
availabilityZone: props.availabilityZone,
assignIpv6AddressOnCreation: props.assignIpv6AddressOnCreation ?? false,
mapPublicIpOnLaunch: props.mapPublicIpOnLaunch ?? undefined,
});

this.node.defaultChild = subnet;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading