feat(ec2): improve subnet selection to support subnet group name and combined selection#35513
feat(ec2): improve subnet selection to support subnet group name and combined selection#35513
Conversation
pahud
left a comment
There was a problem hiding this comment.
Thank you for the PR.
packages/aws-cdk-lib/aws-ec2/test/integ.subnet-selection-combined.ts
let's move this integ test to packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test and
$ cd framework-integ
$ yarn build --fix
$ yarn integ test/aws-ec2/test/integ.subnet-selection-combined.js --update-on-failed
to generate the new snapshot.
and you may want to
$ yarn integ --directory test/aws-ec2/test/ --update-on-failed
to make sure all existing aws-ec2 integ tests stay up-to-date and refreshed if necessary.
…shots - Move integ.subnet-selection-combined.ts from aws-cdk-lib to framework-integ - Update imports to use proper framework-integ pattern - Convert to use IntegTest construct as required by modern CDK testing - Generate integration test snapshots Addresses review feedback from PR aws#35513
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
…combined selection This change enhances the SubnetSelection functionality to address the issue where users cannot specify exact subnet groups by name when multiple public subnets exist with different purposes. Key improvements: - Add support for subnet_group_name in SubnetSelection - Enable combined subnet selection using both type and name - Maintain backward compatibility with existing subnet selection methods Fixes aws#35422 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
…shots - Move integ.subnet-selection-combined.ts from aws-cdk-lib to framework-integ - Update imports to use proper framework-integ pattern - Convert to use IntegTest construct as required by modern CDK testing - Generate integration test snapshots Addresses review feedback from PR aws#35513
62b7275 to
260af5f
Compare
…r simpler alternatives - Add comprehensive JSDoc documentation to selectSubnetObjectsByTypeAndName method - Include guidance about when to use simpler alternatives (subnetGroupName alone, subnetType alone, or SubnetFilter.byIds) - Update README with note about considering simpler alternatives - Improve SubnetSelection interface documentation with usage guidance
pahud
left a comment
There was a problem hiding this comment.
Per CI error:
aws-cdk-lib: /codebuild/output/src1050340690/src/actions-runner/_work/aws-cdk/aws-cdk/packages/aws-cdk-lib/aws-ec2/lib/vpc.ts
aws-cdk-lib: 717:5 error Trailing spaces not allowed no-trailing-spaces
aws-cdk-lib: 722:5 error Trailing spaces not allowed no-trailing-spaces
aws-cdk-lib: ✖ 2 problems (2 errors, 0 warnings)
aws-cdk-lib: 2 errors and 0 warnings potentially fixable with the `--fix` option.
aws-cdk-lib: Error: /codebuild/output/src1050340690/src/actions-runner/_work/aws-cdk/aws-cdk/node_modules/eslint/bin/eslint.js . --ext=.ts --resolve-plugins-relative-to=/codebuild/output/src1050340690/src/actions-runner/_work/aws-cdk/aws-cdk/tools/@aws-cdk/cdk-build-tools/lib exited with error code 1
please run yarn lint --fix in aws-cdk-lib
Addresses PR review comment about ESLint trailing spaces errors on lines 717 and 722.
rix0rrr
left a comment
There was a problem hiding this comment.
Looking at the original issue, it's not clear to me how the recommended:
subnet_group_name="public" # Specify your desired group name
solution is not sufficient.
Subnet groups of a given name are already of a defined type.
In other words in the following example:
# Combine type and group name for precise selection
subnets = ec2.SubnetSelection(
subnet_group_name="public"
subnet_type=ec2.SubnetType.PUBLIC,
)
Once we know that subnet_group_name="public", it must already follow that subnet_type=PUBLIC.
If you passed in any other value than PUBLIC here, you would always get an empty set.
It might be that the original reporter actually had an unfixable problem because there is a bug in the code, but if they do this is not the solution to it.
|
This PR has been in the CHANGES REQUESTED state for 3 weeks, and looks abandoned. Note that PRs with failing linting check or builds are not reviewed, please ensure your build is passing To prevent automatic closure:
This PR will automatically close in 14 days if no action is taken. |
|
This PR has been deemed to be abandoned, and will be automatically closed. Please create a new PR for these changes if you think this decision has been made in error. |
|
Comments on closed issues and PRs are hard for our team to see. |
Summary
This PR addresses issue #35422 by enhancing the
SubnetSelectionfunctionality to support more precise subnet selection when multiple public subnets with different purposes exist in a VPC.Problem
Currently, when using
SubnetSelection(subnet_type=SubnetType.PUBLIC), the CDK selects any public subnet without considering the specific subnet group name. This causes issues when users have multiple public subnet groups (e.g., "public" and "nat") and need to target a specific group.Solution
This PR introduces the following enhancements:
subnet_typeandsubnet_group_namefor more precise selectionChanges Made
Usage Examples
Testing
Breaking Changes
None. This change is fully backward compatible.
Fixes #35422