diff --git a/packages/@aws-cdk/aws-events/lib/event-bus.ts b/packages/@aws-cdk/aws-events/lib/event-bus.ts index daeb6060c11a5..ee953f5622634 100644 --- a/packages/@aws-cdk/aws-events/lib/event-bus.ts +++ b/packages/@aws-cdk/aws-events/lib/event-bus.ts @@ -269,16 +269,18 @@ export class EventBus extends EventBusBase { } if (eventSourceName !== undefined) { - // Ex: aws.partner/PartnerName/acct1/repo1 - const eventSourceNameRegex = /^aws\.partner(\/[\.\-_A-Za-z0-9]+){2,}$/; - if (!eventSourceNameRegex.test(eventSourceName)) { - throw new Error( - `'eventSourceName' must satisfy: ${eventSourceNameRegex}`, - ); - } else if (!eventBusNameRegex.test(eventSourceName)) { - throw new Error( - `'eventSourceName' must satisfy: ${eventBusNameRegex}`, - ); + if (!Token.isUnresolved(eventSourceName)) { + // Ex: aws.partner/PartnerName/acct1/repo1 + const eventSourceNameRegex = /^aws\.partner(\/[\.\-_A-Za-z0-9]+){2,}$/; + if (!eventSourceNameRegex.test(eventSourceName)) { + throw new Error( + `'eventSourceName' must satisfy: ${eventSourceNameRegex}`, + ); + } else if (!eventBusNameRegex.test(eventSourceName)) { + throw new Error( + `'eventSourceName' must satisfy: ${eventBusNameRegex}`, + ); + } } return { eventBusName: eventSourceName, eventSourceName }; } diff --git a/packages/@aws-cdk/aws-events/test/event-bus.test.ts b/packages/@aws-cdk/aws-events/test/event-bus.test.ts index 34406986c608e..11b58d028c773 100644 --- a/packages/@aws-cdk/aws-events/test/event-bus.test.ts +++ b/packages/@aws-cdk/aws-events/test/event-bus.test.ts @@ -254,6 +254,16 @@ describe('event bus', () => { }).toThrow(/'eventSourceName' must satisfy: \/\^aws/); }); + test('does not throw if eventSourceName is a token', () => { + // GIVEN + const stack = new Stack(); + + // WHEN / THEN + expect(() => new EventBus(stack, 'EventBus', { + eventSourceName: Aws.STACK_NAME, + })).not.toThrow(); + }); + test('event bus source name cannot be empty string', () => { // GIVEN const stack = new Stack();