Skip to content

Commit 168a98f

Browse files
authoredNov 29, 2021
fix(aws-elasticloadbalancingv2): Set stickiness.enabled unless target type is lambda (#17271)
Avoid setting `stickiness.enabled` to `false` when the target group type is lambda as it breaks on deployment. Fixes #17261. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 171cbc1 commit 168a98f

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed
 

‎packages/@aws-cdk/aws-elasticloadbalancingv2-targets/test/integ.lambda-target.expected.json

-6
Original file line numberDiff line numberDiff line change
@@ -404,12 +404,6 @@
404404
"LBListenerTargetsGroup76EF81E8": {
405405
"Type": "AWS::ElasticLoadBalancingV2::TargetGroup",
406406
"Properties": {
407-
"TargetGroupAttributes": [
408-
{
409-
"Key": "stickiness.enabled",
410-
"Value": "false"
411-
}
412-
],
413407
"Targets": [
414408
{
415409
"Id": {

‎packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-target-group.ts

+4
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ export class ApplicationTargetGroup extends TargetGroupBase implements IApplicat
166166
const result = target.attachToApplicationTargetGroup(this);
167167
this.addLoadBalancerTarget(result);
168168
}
169+
170+
if (this.targetType === TargetType.LAMBDA) {
171+
this.setAttribute('stickiness.enabled', undefined);
172+
}
169173
}
170174

171175
/**

‎packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/target-group.test.ts

+27
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,33 @@ describe('tests', () => {
2020
}).toThrow(/'vpc' is required for a non-Lambda TargetGroup/);
2121
});
2222

23+
test('Lambda target should not have stickiness.enabled set', () => {
24+
const app = new cdk.App();
25+
const stack = new cdk.Stack(app, 'Stack');
26+
27+
new elbv2.ApplicationTargetGroup(stack, 'TG', {
28+
targetType: elbv2.TargetType.LAMBDA,
29+
});
30+
31+
const tg = new elbv2.ApplicationTargetGroup(stack, 'TG2');
32+
tg.addTarget({
33+
attachToApplicationTargetGroup(_targetGroup: elbv2.IApplicationTargetGroup): elbv2.LoadBalancerTargetProps {
34+
return {
35+
targetType: elbv2.TargetType.LAMBDA,
36+
targetJson: { id: 'arn:aws:lambda:eu-west-1:123456789012:function:myFn' },
37+
};
38+
},
39+
});
40+
41+
expect(stack).not.toHaveResourceLike('AWS::ElasticLoadBalancingV2::TargetGroup', {
42+
TargetGroupAttributes: [
43+
{
44+
Key: 'stickiness.enabled',
45+
},
46+
],
47+
});
48+
});
49+
2350
test('Can add self-registering target to imported TargetGroup', () => {
2451
// GIVEN
2552
const app = new cdk.App();

0 commit comments

Comments
 (0)
Please sign in to comment.