Skip to content

fix(ec2): vpc interface endpoint not attaching to selected subnets (#…#37179

Closed
Aaxhirrr wants to merge 3 commits intoaws:mainfrom
Aaxhirrr:fix/vpc-endpoint-cfn-subnets
Closed

fix(ec2): vpc interface endpoint not attaching to selected subnets (#…#37179
Aaxhirrr wants to merge 3 commits intoaws:mainfrom
Aaxhirrr:fix/vpc-endpoint-cfn-subnets

Conversation

@Aaxhirrr
Copy link
Copy Markdown

@Aaxhirrr Aaxhirrr commented Mar 6, 2026

fix(ec2): vpc interface endpoint not attaching to selected subnets (#37144)

CfnSubnet objects passed within SubnetSelection are now automatically wrapped with Subnet.fromSubnetAttributes to ensure they can be used for things like interface endpoint SubnetIds.

Issue # (if applicable)

Closes #37144

Reason for this change

When creating a VPC interface endpoint and passing CfnSubnet objects directly into the subnets array of SubnetSelection, the generated CloudFormation template results in an empty SubnetIds array. This is because CfnSubnet is an L1 construct and does not implement the full ISubnet interface, specifically lacking the .subnetId property that the endpoint selection logic relies on, causing it to fail silently.

Description of changes

  • Updated Vpc.selectSubnetObjects in @aws-cdk/aws-ec2 to intercept SubnetSelection.subnets arrays.
  • It now checks if any explicitly provided subnets are instances of CfnSubnet.
  • If found, it automatically wraps them in a singleton wrapper using Subnet.fromSubnetAttributes(this, id, { subnetId: s.ref, ... }), retaining their availability zone and CIDR block properties if available.
  • This allows vpc-endpoint constructs (and anything else utilizing selectSubnetObjects) to extract the proper routing IDs during CloudFormation synthesis.

Describe any new or updated permissions being added

N/A - No new permissions or IAM updates are required for this construct logical fix.

Description of how you validated changes

  • Added a new unit test endpoint selection works with L1 CfnSubnet passed as ISubnet in packages/aws-cdk-lib/aws-ec2/test/vpc-endpoint.test.ts.
  • The test explicitly verifies that passing a CfnSubnet to vpc.addInterfaceEndpoint() properly populates the SubnetIds property with the Ref of the CloudFormation subnet in the synthesized output.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

…ws#37144)

CfnSubnet objects passed within SubnetSelection are now automatically wrapped with Subnet.fromSubnetAttributes to ensure they can be used for things like interface endpoint SubnetIds.
@github-actions github-actions bot added effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 labels Mar 6, 2026
@aws-cdk-automation aws-cdk-automation requested a review from a team March 6, 2026 05:39
@github-actions github-actions bot added the beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK label Mar 6, 2026
Copy link
Copy Markdown
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter fails with the following errors:

❌ Fixes must contain a change to an integration test file and the resulting snapshot.

If you believe this pull request should receive an exemption, please comment and provide a justification. A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed, add Clarification Request to a comment.

Adding integration test. Snapshot must be generated by maintainer via CI as local build environment is incompatible.
…property access

The build failed because Subnet was not correctly imported from within vpc.ts (where it is defined) and because selection.subnets was being mapped without casting s to CfnSubnet, leading to property access errors on ISubnet.
@aws-cdk-automation
Copy link
Copy Markdown
Collaborator

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:

  • Resume work on the PR
  • OR request an exemption by adding a comment containing 'Exemption Request' with justification e.x "Exemption Request: "
  • OR request clarification by adding a comment containing 'Clarification Request' with a question e.x "Clarification Request: "

This PR will automatically close in 14 days if no action is taken.

@aws-cdk-automation
Copy link
Copy Markdown
Collaborator

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.

@aws-cdk-automation aws-cdk-automation added the closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. label Apr 11, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 11, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ec2: vpc interface endpoint not attaching to selected subnets

2 participants