Skip to content

Commit 5d71d8e

Browse files
authored
chore(elasticloadbalancingv2): Add stickiness cookie duration checks (#13263)
One little extra check rather than finding this out during the ALB deployment process. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 23385dd commit 5d71d8e

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ export class ApplicationTargetGroup extends TargetGroupBase implements IApplicat
151151
* @see https://docs.aws.amazon.com/elasticloadbalancing/latest/application/sticky-sessions.html
152152
*/
153153
public enableCookieStickiness(duration: Duration, cookieName?: string) {
154+
if (duration.toSeconds() < 1 || duration.toSeconds() > 604800) {
155+
throw new Error('Stickiness cookie duration value must be between 1 second and 7 days (604800 seconds).');
156+
}
154157
if (cookieName !== undefined) {
155158
if (!Token.isUnresolved(cookieName) && (cookieName.startsWith('AWSALB') || cookieName.startsWith('AWSALBAPP') || cookieName.startsWith('AWSALBTG'))) {
156159
throw new Error('App cookie names that start with the following prefixes are not allowed: AWSALB, AWSALBAPP, and AWSALBTG; they\'re reserved for use by the load balancer.');

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

+15
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,19 @@ describe('tests', () => {
190190
});
191191
}).toThrow(/App cookie name cannot be an empty string./);
192192
});
193+
194+
test('Bad stickiness duration value', () => {
195+
// GIVEN
196+
const app = new cdk.App();
197+
const stack = new cdk.Stack(app, 'Stack');
198+
const vpc = new ec2.Vpc(stack, 'VPC', {});
199+
200+
// THEN
201+
expect(() => {
202+
new elbv2.ApplicationTargetGroup(stack, 'TargetGroup', {
203+
stickinessCookieDuration: cdk.Duration.days(8),
204+
vpc,
205+
});
206+
}).toThrow(/Stickiness cookie duration value must be between 1 second and 7 days \(604800 seconds\)./);
207+
});
193208
});

0 commit comments

Comments
 (0)