Skip to content

Conversation

@kawabata-mcl
Copy link
Contributor

Issue # (if applicable)

None

Reason for this change

We can set a multi-value headers property for a lambda target group from cloudformation, but this was not supported in the AWS CDK L2 construct.

Description of changes

Add multiValueHeadersEnabled property to ApplicationTargetGroupProps and set it in the ApplicationTargetGroup constructor.

Describe any new or updated permissions being added

None

Description of how you validated changes

Added both unit and integration 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 April 29, 2025 16:10
@github-actions github-actions bot added beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK p2 labels Apr 29, 2025
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Apr 30, 2025
Copy link
Contributor

@badmintoncryer badmintoncryer left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution! Most of changes are seems to be good, and I've added some small comments.

Comment on lines 116 to 117
* The possible values are true or false.
* The default value is false.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it seems redundant. Could you please remove them?

Suggested change
* The possible values are true or false.
* The default value is false.

Comment on lines 889 to 922
test('lambda.multi_value_headers.enabled is not set when multiValueHeadersEnabled is false', () => {
// GIVEN
const app = new cdk.App();
const stack = new cdk.Stack(app, 'Stack');

// WHEN
new elbv2.ApplicationTargetGroup(stack, 'TG', {
targetType: elbv2.TargetType.LAMBDA,
multiValueHeadersEnabled: false,
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::ElasticLoadBalancingV2::TargetGroup', {
TargetType: 'lambda',
TargetGroupAttributes: Match.absent(),
});
});

test('lambda.multi_value_headers.enabled is not set when multiValueHeadersEnabled is not specified', () => {
// GIVEN
const app = new cdk.App();
const stack = new cdk.Stack(app, 'Stack');

// WHEN
new elbv2.ApplicationTargetGroup(stack, 'TG', {
targetType: elbv2.TargetType.LAMBDA,
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::ElasticLoadBalancingV2::TargetGroup', {
TargetType: 'lambda',
TargetGroupAttributes: Match.absent(),
});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please use test.each?

Suggested change
test('lambda.multi_value_headers.enabled is not set when multiValueHeadersEnabled is false', () => {
// GIVEN
const app = new cdk.App();
const stack = new cdk.Stack(app, 'Stack');
// WHEN
new elbv2.ApplicationTargetGroup(stack, 'TG', {
targetType: elbv2.TargetType.LAMBDA,
multiValueHeadersEnabled: false,
});
// THEN
Template.fromStack(stack).hasResourceProperties('AWS::ElasticLoadBalancingV2::TargetGroup', {
TargetType: 'lambda',
TargetGroupAttributes: Match.absent(),
});
});
test('lambda.multi_value_headers.enabled is not set when multiValueHeadersEnabled is not specified', () => {
// GIVEN
const app = new cdk.App();
const stack = new cdk.Stack(app, 'Stack');
// WHEN
new elbv2.ApplicationTargetGroup(stack, 'TG', {
targetType: elbv2.TargetType.LAMBDA,
});
// THEN
Template.fromStack(stack).hasResourceProperties('AWS::ElasticLoadBalancingV2::TargetGroup', {
TargetType: 'lambda',
TargetGroupAttributes: Match.absent(),
});
});
test.each([false, undefined])('lambda.multi_value_headers.enabled is not set when multiValueHeadersEnabled is %s', (multiValueHeadersEnabled) => {
// GIVEN
const app = new cdk.App();
const stack = new cdk.Stack(app, 'Stack');
// WHEN
new elbv2.ApplicationTargetGroup(stack, 'TG', {
targetType: elbv2.TargetType.LAMBDA,
multiValueHeadersEnabled,
});
// THEN
Template.fromStack(stack).hasResourceProperties('AWS::ElasticLoadBalancingV2::TargetGroup', {
TargetType: 'lambda',
TargetGroupAttributes: Match.absent(),
});
});

Comment on lines 987 to 1013
test('Throws an error when multiValueHeadersEnabled is true for non-Lambda target type (IP)', () => {
// GIVEN
const app = new cdk.App();
const stack = new cdk.Stack(app, 'Stack');
const vpc = new ec2.Vpc(stack, 'VPC');

// WHEN & THEN
expect(() => new elbv2.ApplicationTargetGroup(stack, 'TargetGroup', {
vpc,
targetType: elbv2.TargetType.IP,
multiValueHeadersEnabled: true,
})).toThrow('multiValueHeadersEnabled is only supported for Lambda targets.');
});

test('Throws an error when multiValueHeadersEnabled is true for non-Lambda target type (Instance)', () => {
// GIVEN
const app = new cdk.App();
const stack = new cdk.Stack(app, 'Stack');
const vpc = new ec2.Vpc(stack, 'VPC');

// WHEN & THEN
expect(() => new elbv2.ApplicationTargetGroup(stack, 'TargetGroup', {
vpc,
targetType: elbv2.TargetType.INSTANCE,
multiValueHeadersEnabled: true,
})).toThrow('multiValueHeadersEnabled is only supported for Lambda targets.');
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
test('Throws an error when multiValueHeadersEnabled is true for non-Lambda target type (IP)', () => {
// GIVEN
const app = new cdk.App();
const stack = new cdk.Stack(app, 'Stack');
const vpc = new ec2.Vpc(stack, 'VPC');
// WHEN & THEN
expect(() => new elbv2.ApplicationTargetGroup(stack, 'TargetGroup', {
vpc,
targetType: elbv2.TargetType.IP,
multiValueHeadersEnabled: true,
})).toThrow('multiValueHeadersEnabled is only supported for Lambda targets.');
});
test('Throws an error when multiValueHeadersEnabled is true for non-Lambda target type (Instance)', () => {
// GIVEN
const app = new cdk.App();
const stack = new cdk.Stack(app, 'Stack');
const vpc = new ec2.Vpc(stack, 'VPC');
// WHEN & THEN
expect(() => new elbv2.ApplicationTargetGroup(stack, 'TargetGroup', {
vpc,
targetType: elbv2.TargetType.INSTANCE,
multiValueHeadersEnabled: true,
})).toThrow('multiValueHeadersEnabled is only supported for Lambda targets.');
});
test.each([elbv2.TargetType.IP, elbv2.TargetType.INSTANCE])('Throws an error when multiValueHeadersEnabled is true for non-Lambda target type (%s)', (targetType) => {
// GIVEN
const app = new cdk.App();
const stack = new cdk.Stack(app, 'Stack');
const vpc = new ec2.Vpc(stack, 'VPC');
// WHEN & THEN
expect(() => new elbv2.ApplicationTargetGroup(stack, 'TargetGroup', {
vpc,
targetType,
multiValueHeadersEnabled: true,
})).toThrow('multiValueHeadersEnabled is only supported for Lambda targets.');
});


### Multi-Value Headers with Lambda Targets

When using a Lambda function as a target, you can enable multi-value headers to allow the load balancer to send headers with multiple values:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is better to add documentation link.

Suggested change
When using a Lambda function as a target, you can enable multi-value headers to allow the load balancer to send headers with multiple values:
When using a Lambda function as a target, you can enable [multi-value headers](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html#multi-value-headers) to allow the load balancer to send headers with multiple values:

@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Apr 30, 2025
…r multi-value headers in Lambda target groups
@kawabata-mcl
Copy link
Contributor Author

@badmintoncryer
Thanks for the review.
I fixed everything you mentioned.

Copy link
Contributor

@badmintoncryer badmintoncryer left a comment

Choose a reason for hiding this comment

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

Thanks!

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Apr 30, 2025
@scorbiere scorbiere self-assigned this May 9, 2025
scorbiere
scorbiere previously approved these changes May 9, 2025
Copy link
Contributor

@scorbiere scorbiere left a comment

Choose a reason for hiding this comment

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

Thanks @kawabata-mcl for your contribution.

Note: We usually try to add assertion(s) in the integ test, but in this current case, I think it would make the integ test very complex. That's why I am not asking for this change.

@mergify mergify bot dismissed scorbiere’s stale review May 9, 2025 17:28

Pull request has been modified.

@mergify
Copy link
Contributor

mergify bot commented May 9, 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).

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label May 9, 2025
@mergify
Copy link
Contributor

mergify bot commented May 9, 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).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

@mergify
Copy link
Contributor

mergify bot commented May 9, 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 c8b98e7 into aws:main May 9, 2025
14 of 15 checks passed
@github-actions
Copy link
Contributor

github-actions bot commented May 9, 2025

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 May 9, 2025
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 p2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants