diff --git a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-load-balancer.ts b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-load-balancer.ts index 43af694e9ae20..bb6f2cfbefb8d 100644 --- a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-load-balancer.ts +++ b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-load-balancer.ts @@ -127,6 +127,11 @@ export class ApplicationLoadBalancer extends BaseLoadBalancer implements IApplic if (props.dropInvalidHeaderFields) {this.setAttribute('routing.http.drop_invalid_header_fields.enabled', 'true'); } if (props.desyncMitigationMode !== undefined) {this.setAttribute('routing.http.desync_mitigation_mode', props.desyncMitigationMode); } if (props.clientKeepAlive !== undefined) { + const clientKeepAliveInMillis = props.clientKeepAlive.toMilliseconds(); + if (clientKeepAliveInMillis < 1000) { + throw new Error(`\'clientKeepAlive\' must be between 60 and 604800 seconds. Got: ${clientKeepAliveInMillis} milliseconds`); + } + const clientKeepAliveInSeconds = props.clientKeepAlive.toSeconds(); if (clientKeepAliveInSeconds < 60 || clientKeepAliveInSeconds > 604800) { throw new Error(`\'clientKeepAlive\' must be between 60 and 604800 seconds. Got: ${clientKeepAliveInSeconds} seconds`); diff --git a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/test/alb/load-balancer.test.ts b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/test/alb/load-balancer.test.ts index 119fa890527bc..54f2b5b1a4b7d 100644 --- a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/test/alb/load-balancer.test.ts +++ b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/test/alb/load-balancer.test.ts @@ -112,7 +112,7 @@ describe('tests', () => { }); }); - test.each([59, 604801])('throw error for invalid clientKeepAlive', (duration) => { + test.each([59, 604801])('throw error for invalid clientKeepAlive in seconds', (duration) => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'Stack'); @@ -126,6 +126,20 @@ describe('tests', () => { }).toThrow(`\'clientKeepAlive\' must be between 60 and 604800 seconds. Got: ${duration} seconds`); }); + test('throw errer for invalid clientKeepAlive in milliseconds', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'Stack'); + + // THEN + expect(() => { + new elbv2.ApplicationLoadBalancer(stack, 'LB', { + vpc, + clientKeepAlive: cdk.Duration.millis(100), + }); + }).toThrow('\'clientKeepAlive\' must be between 60 and 604800 seconds. Got: 100 milliseconds'); + }); + describe('Desync mitigation mode', () => { test('Defensive', () => { // GIVEN