Skip to content

Commit

Permalink
fix(lambda-event-sources): event source property maxConcurrency is no…
Browse files Browse the repository at this point in the history
…t 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*
  • Loading branch information
rahman authored Nov 20, 2023
1 parent b01e17d commit 38f54db
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 38f54db

Please sign in to comment.