Skip to content

feat(elasticloadbalancingv2): subnet mappings for network load balancer #33736

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Apr 11, 2025

Conversation

badmintoncryer
Copy link
Contributor

@badmintoncryer badmintoncryer commented Mar 11, 2025

Issue # (if applicable)

Closes #9696.

Reason for this change

Cloudformation supports the configuration of subnet information through subnetMapping more detailed than using subnetIds but AWS CDK doesn't support this.

https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/aws-properties-elasticloadbalancingv2-loadbalancer-subnetmapping.html

Description of changes

  • Add subnetMappings to NetworkLoadBalancerProps
  • Define SourceNatIpv6Prefix class and SubnetMapping interface at base-loadbalancer.ts

Describe any new or updated permissions being added

None

Description of how you validated changes

Add both unit and integ tests

Checklist


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

@aws-cdk-automation aws-cdk-automation requested a review from a team March 11, 2025 15:18
@github-actions github-actions bot added effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p1 distinguished-contributor [Pilot] contributed 50+ PRs to the CDK labels Mar 11, 2025
Copy link
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.

(This review is outdated)

Copy link

codecov bot commented Mar 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.98%. Comparing base (74cbe27) to head (0de13ae).
Report is 27 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #33736   +/-   ##
=======================================
  Coverage   83.98%   83.98%           
=======================================
  Files         120      120           
  Lines        6976     6976           
  Branches     1178     1178           
=======================================
  Hits         5859     5859           
  Misses       1005     1005           
  Partials      112      112           
Flag Coverage Δ
suite.unit 83.98% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
packages/aws-cdk ∅ <ø> (∅)
packages/aws-cdk-lib/core 83.98% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@aws-cdk-automation aws-cdk-automation dismissed their stale review March 17, 2025 22:23

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

Comment on lines +294 to +296
if (props.internetFacing !== true && props.subnetMappings.some(sm => sm.allocationId !== undefined)) {
throw new ValidationError('Cannot specify `allocationId` for a internal load balancer.', this);
}
Copy link
Contributor Author

@badmintoncryer badmintoncryer Mar 18, 2025

Choose a reason for hiding this comment

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

This setting causes deployment failure.

Resource handler returned message: "Elastic IPs are not supported for load balancers with scheme 'internal' (Service: ElasticLoadBalancingV2, Status Code: 400, Request ID: 37af9234-ae03-4bc7-a8a5-3a3bc5e08eba) (SDK Attempt Count: 1)" (RequestToken: 7e147881-8745-a761-4deb-0dea575f6352, HandlerErrorCode: InvalidRequest)

Comment on lines +297 to +299
if (props.enablePrefixForIpv6SourceNat !== true && props.subnetMappings.some(sm => sm.sourceNatIpv6Prefix !== undefined)) {
throw new ValidationError('Cannot specify `sourceNatIpv6Prefix` for a load balancer that does not have `enablePrefixForIpv6SourceNat` enabled.', this);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This setting causes deployment failure.

Resource handler returned message: "'EnablePrefixForIpv6SourceNat' must be set to 'on', before 'SourceNatIpv6Prefix' can be specified. (Service: ElasticLoadBalancingV2, Status Code: 400, Request ID: 68ca21fc-6c22-4375-86f5-4fa27b0a7e7b) (SDK Attempt Count: 1)" (RequestToken: f07c93ee-f6ea-d3ad-e24b-9724d5611526, HandlerErrorCode: InvalidRequest)

/**
* Specifies a subnet for a load balancer
*/
export interface SubnetMapping {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, subnetMapping exists only as a configuration item for NLB, but I defined it in base-loadbalancer.ts in anticipation that items for ALB may be added in the future.

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Mar 21, 2025
@paulhcsun paulhcsun self-assigned this Apr 9, 2025
Copy link
Contributor

@paulhcsun paulhcsun left a comment

Choose a reason for hiding this comment

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

Overall this lgtm, just left a few minor comments.

Comment on lines 336 to 338
internetConnectivityEstablished = baseProps.vpc.selectSubnets(
{ subnetFilters: [ec2.SubnetFilter.byIds(mappedSubnetIds)] },
).internetConnectivityEstablished;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: could we rename this variable so it has a different name from the actual property that we're checking when filtering. It feels a bit confusing if they're named the same.

Suggested change
internetConnectivityEstablished = baseProps.vpc.selectSubnets(
{ subnetFilters: [ec2.SubnetFilter.byIds(mappedSubnetIds)] },
).internetConnectivityEstablished;
internetConnectivityEstablishedSubnets = baseProps.vpc.selectSubnets(
{ subnetFilters: [ec2.SubnetFilter.byIds(mappedSubnetIds)] },
).internetConnectivityEstablished;

paulhcsun
paulhcsun previously approved these changes Apr 11, 2025
Copy link
Contributor

@paulhcsun paulhcsun left a comment

Choose a reason for hiding this comment

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

Great stuff! Thank you for your contribution on this highly requested feature!

@paulhcsun
Copy link
Contributor

@Mergifyio update

Copy link
Contributor

mergify bot commented Apr 11, 2025

update

☑️ Nothing to do

  • #commits-behind > 0 [📌 update requirement]
  • -closed [📌 update requirement]
  • -conflict [📌 update requirement]
  • queue-position = -1 [📌 update requirement]

@mergify mergify bot dismissed paulhcsun’s stale review April 11, 2025 18:04

Pull request has been modified.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 0de13ae
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Copy link
Contributor

mergify bot commented Apr 11, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit c6905c6 into aws:main Apr 11, 2025
23 checks passed
Copy link
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, 2025
@badmintoncryer badmintoncryer deleted the 9696-subnetMapping branch April 11, 2025 23:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
distinguished-contributor [Pilot] contributed 50+ PRs to the CDK effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p1 pr/needs-maintainer-review This PR needs a review from a Core Team Member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[aws-elasticloadbalancingv2] Add support for SubnetMapping to Network Load Balancer
3 participants