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,