-
Notifications
You must be signed in to change notification settings - Fork 4.3k
feat(elasticloadbalancingv2): add support for multi-value headers in Lambda target groups #34298
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
Conversation
…Lambda target groups
…adersEnabled and executed integ test
…gets imports for multi-value headers
badmintoncryer
left a comment
There was a problem hiding this 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.
| * The possible values are true or false. | ||
| * The default value is false. |
There was a problem hiding this comment.
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?
| * The possible values are true or false. | |
| * The default value is false. |
| 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(), | ||
| }); | ||
| }); |
There was a problem hiding this comment.
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?
| 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(), | |
| }); | |
| }); |
| 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.'); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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: |
There was a problem hiding this comment.
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.
| 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: |
…r multi-value headers in Lambda target groups
|
@badmintoncryer |
badmintoncryer
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
scorbiere
left a comment
There was a problem hiding this 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.
|
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). |
|
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 CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
|
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). |
|
Comments on closed issues and PRs are hard for our team to see. |
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