Skip to content

Commit

Permalink
fix(aws-elasticloadbalancingv2): Set stickiness.enabled unless target…
Browse files Browse the repository at this point in the history
… 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*
  • Loading branch information
topecongiro committed Nov 29, 2021
1 parent 171cbc1 commit 168a98f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
Expand Up @@ -404,12 +404,6 @@
"LBListenerTargetsGroup76EF81E8": {
"Type": "AWS::ElasticLoadBalancingV2::TargetGroup",
"Properties": {
"TargetGroupAttributes": [
{
"Key": "stickiness.enabled",
"Value": "false"
}
],
"Targets": [
{
"Id": {
Expand Down
Expand Up @@ -166,6 +166,10 @@ export class ApplicationTargetGroup extends TargetGroupBase implements IApplicat
const result = target.attachToApplicationTargetGroup(this);
this.addLoadBalancerTarget(result);
}

if (this.targetType === TargetType.LAMBDA) {
this.setAttribute('stickiness.enabled', undefined);
}
}

/**
Expand Down
Expand Up @@ -20,6 +20,33 @@ describe('tests', () => {
}).toThrow(/'vpc' is required for a non-Lambda TargetGroup/);
});

test('Lambda target should not have stickiness.enabled set', () => {
const app = new cdk.App();
const stack = new cdk.Stack(app, 'Stack');

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

const tg = new elbv2.ApplicationTargetGroup(stack, 'TG2');
tg.addTarget({
attachToApplicationTargetGroup(_targetGroup: elbv2.IApplicationTargetGroup): elbv2.LoadBalancerTargetProps {
return {
targetType: elbv2.TargetType.LAMBDA,
targetJson: { id: 'arn:aws:lambda:eu-west-1:123456789012:function:myFn' },
};
},
});

expect(stack).not.toHaveResourceLike('AWS::ElasticLoadBalancingV2::TargetGroup', {
TargetGroupAttributes: [
{
Key: 'stickiness.enabled',
},
],
});
});

test('Can add self-registering target to imported TargetGroup', () => {
// GIVEN
const app = new cdk.App();
Expand Down

0 comments on commit 168a98f

Please sign in to comment.