From 38f54dbd01722baf7781a006da75e109d38cd9db Mon Sep 17 00:00:00 2001 From: Adam Rahman <7253657+rahman@users.noreply.github.com> Date: Mon, 20 Nov 2023 18:08:14 +0000 Subject: [PATCH] fix(lambda-event-sources): event source property maxConcurrency is not token-aware (#27797) Allows a Token to be provided for maxConcurrency without runtime errors Closes #27796. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .../aws-cdk-lib/aws-lambda/lib/event-source-mapping.ts | 2 +- .../aws-lambda/test/event-source-mapping.test.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/aws-cdk-lib/aws-lambda/lib/event-source-mapping.ts b/packages/aws-cdk-lib/aws-lambda/lib/event-source-mapping.ts index c1672b21d58d7..38c7865dc70a8 100644 --- a/packages/aws-cdk-lib/aws-lambda/lib/event-source-mapping.ts +++ b/packages/aws-cdk-lib/aws-lambda/lib/event-source-mapping.ts @@ -345,7 +345,7 @@ export class EventSourceMapping extends cdk.Resource implements IEventSourceMapp throw new Error(`maxBatchingWindow cannot be over 300 seconds, got ${props.maxBatchingWindow.toSeconds()}`); } - if (props.maxConcurrency && (props.maxConcurrency < 2 || props.maxConcurrency > 1000)) { + if (props.maxConcurrency && !cdk.Token.isUnresolved(props.maxConcurrency) && (props.maxConcurrency < 2 || props.maxConcurrency > 1000)) { throw new Error('maxConcurrency must be between 2 and 1000 concurrent instances'); } diff --git a/packages/aws-cdk-lib/aws-lambda/test/event-source-mapping.test.ts b/packages/aws-cdk-lib/aws-lambda/test/event-source-mapping.test.ts index 2a5e15046bfd6..8182a15406db7 100644 --- a/packages/aws-cdk-lib/aws-lambda/test/event-source-mapping.test.ts +++ b/packages/aws-cdk-lib/aws-lambda/test/event-source-mapping.test.ts @@ -60,6 +60,14 @@ describe('event source mapping', () => { })).toThrow(/maxConcurrency must be between 2 and 1000 concurrent instances/); }); + test('does not throw if maxConcurrency is a token', () => { + expect(() => new EventSourceMapping(stack, 'test', { + target: fn, + eventSourceArn: '', + maxConcurrency: cdk.Token.asNumber({ Ref: 'abc' }), + })).not.toThrow(); + }); + test('maxConcurrency appears in stack', () => { new EventSourceMapping(stack, 'test', { target: fn,