aws / aws/aws-cdk

ec2: Dual Stack VPC Additions

Open
#33,490 3 comments 1 reaction 0 assignees View on GitHub
@aws-cdk/aws-ec2 effort/medium feature-request p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the feature

These comments [#1](https://github.com/aws/aws-cdk/pull/28480/files#r1435751880) and [#2 ](https://github.com/aws/aws-cdk/pull/28480/files#r1435752394) were left out of https://github.com/aws/aws-cdk/pull/28480 to automatically enable `enable_dns64` and configure `private_dns_name_options_on_launch` in the respective subnet in dual stack mode.

To quote @sgryphon:

> Set enable_dns64 = true (if protocol is dual stack), will simplify creation of IPv6-only machines on the VPC
> ...
> NOTE: You need to have NAT64 routes set up before enabling this.

> Also set private_dns_name_options_on_launch. For IPv6-only subnets, this is automatically enabled, however for dual-stack the default is not, which means they will get an IPv4 internal DNS name but not IPv6. Note this only applies to internal DNS names.
> This is not yet fully mapped to CloudFormation, so you just need to pass in an array of any with the known properties. Set: EnableResourceNameDnsAAAARecord = true, EnableResourceNameDnsARecord = true, HostnameType = 'resource-name'.

### Use Case

When using dual stack mode, setting enable_dns64 = true will simplify the creation of IPv6-only machines in the VPC so that ipv6-only clients within a dual stack subnet are able to resolve and communicate with IPv4-only external resources.

And properly configuring (or setting sensible defaults) `private_dns_name_options_on_launch` in public/private/isolated subnets will allow machines created on the dual stack subnet to have a machine name based on the instance and be accessible via internal DNS by that name.

### Proposed Solution

Additions will need to be made [here](https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-ec2/lib/vpc.ts#L2093-L2098).

### Other Information

My workaround right now is to do the following:

```python3
...

# Set dns64 for all subnets
for subnet in self._vpc.select_subnets().subnets:
cfn_subnet = cast(ec2.CfnSubnet, subnet.node.default_child)

# IMPORTANT: Enable DNS64 for the subnet to allow ipv6-only clients within this (dual stack) subnet
# to resolve and communicate with IPv4-only external resources.
# NOTE: As of this writing, CDK does not take care of this automatically, so we need to set it manually:
# see this comment: https://github.com/aws/aws-cdk/pull/28480/files#r1435750733
cfn_subnet.enable_dns64 = True

...

# Get all public subnets in our VPC. We need to cast to `ec2.Subnet` as `select_subnets()`
# returns a `ISubnet` which doesn't have the `add_route` method
public_subnets = cast(Sequence[ec2.Subnet], self._vpc.select_subnets(subnet_type=ec2.SubnetType.PUBLIC).subnets)

# For public subnets, ensure they have a route to the internet gateway
for public_subnet in public_subnets:
# Get the internet gateway for the VPC
self._internet_gateway_id = self._vpc.internet_gateway_id

# Ensure the internet gateway is created before we create the routes
public_subnet.node.add_dependency(self._internet_gateway_id)

cfn_public_subnet = cast(ec2.CfnSubnet, public_subnet.node.default_child)

# Enables the creation of AAAA records (IPv6 addresses).
# Enables the creation of A records (IPv4 addresses).
# IMPORTANT: CDK doesn't support this automatically, so we set it manually.
# See comment in PR: https://github.com/aws/aws-cdk/pull/28480/files#r1435752394
# And the current (as of this writing) source code which doesn't set this: https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-ec2/lib/vpc.ts#L2098
cfn_public_subnet.private_dns_name_options_on_launch = {
"EnableResourceNameDnsAAAARecord": True,
"EnableResourceNameDnsARecord": True,
}

...

# Get all private subnets in our VPC. We need to cast to `ec2.Subnet` as `select_subnets()`
# returns a `ISubnet` which doesn't have the `add_route` method
private_subnets = cast(Sequence[ec2.Subnet], self._vpc.select_subnets(subnet_type=ec2.SubnetType.PRIVATE_WITH_EGRESS).subnets)

for private_subnet in private_subnets:
cfn_private_subnet = cast(ec2.CfnSubnet, private_subnet.node.default_child)

# Enables the creation of AAAA records (IPv6 addresses).
# Disables the creation of A records (IPv4 addresses).
# IMPORTANT: CDK doesn't support this automatically, so we set it manually.
# See comment in PR: https://github.com/aws/aws-cdk/pull/28480/files#r1435752394
cfn_private_subnet.private_dns_name_options_on_launch = {
"EnableResourceNameDnsAAAARecord": True,
"EnableResourceNameDnsARecord": False,
}
```

### Acknowledgements

- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change

### CDK version used

2.179.0

### Environment details (OS name and version, etc.)

Darwin

Contributor guide

Open the contributing guide

Research direction

Start in packages/aws-cdk-lib/aws-ec2/lib/vpc.ts at the subnet configuration around lines 2093-2098, then review the linked pull request comments and the existing dual-stack VPC handling. Done means dual-stack subnets configure DNS64 and private DNS name options appropriately for public, private, and isolated subnet behavior, without requiring the documented manual overrides.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cloud, infrastructure, networking
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.