From 8bee193fe66ed0dc3d7751181471a9eb9abae3cc Mon Sep 17 00:00:00 2001 From: Shiv Lakshminarayan Date: Wed, 7 Oct 2020 14:22:14 -0700 Subject: [PATCH] fix(events): cannot use tokens as event bus name (#10772) added a condition to ensure that eventBusName does not contain an unresolved token before performing validation. Closes #10467 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- packages/@aws-cdk/aws-events/lib/event-bus.ts | 4 ++-- .../@aws-cdk/aws-events/test/test.event-bus.ts | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/@aws-cdk/aws-events/lib/event-bus.ts b/packages/@aws-cdk/aws-events/lib/event-bus.ts index db0bf52f65317..2dc1c35c9cded 100644 --- a/packages/@aws-cdk/aws-events/lib/event-bus.ts +++ b/packages/@aws-cdk/aws-events/lib/event-bus.ts @@ -1,5 +1,5 @@ import * as iam from '@aws-cdk/aws-iam'; -import { IResource, Lazy, Resource, Stack } from '@aws-cdk/core'; +import { IResource, Lazy, Resource, Stack, Token } from '@aws-cdk/core'; import { Construct } from 'constructs'; import { CfnEventBus } from './events.generated'; @@ -163,7 +163,7 @@ export class EventBus extends Resource implements IEventBus { throw new Error( '\'eventBusName\' and \'eventSourceName\' cannot both be provided', ); - } else if (eventBusName !== undefined) { + } else if (eventBusName !== undefined && !Token.isUnresolved(eventBusName)) { if (eventBusName === 'default') { throw new Error( '\'eventBusName\' must not be \'default\'', diff --git a/packages/@aws-cdk/aws-events/test/test.event-bus.ts b/packages/@aws-cdk/aws-events/test/test.event-bus.ts index c32824884c08e..a6c32885ec4a9 100644 --- a/packages/@aws-cdk/aws-events/test/test.event-bus.ts +++ b/packages/@aws-cdk/aws-events/test/test.event-bus.ts @@ -1,6 +1,6 @@ import { expect, haveResource } from '@aws-cdk/assert'; import * as iam from '@aws-cdk/aws-iam'; -import { CfnResource, Stack } from '@aws-cdk/core'; +import { Aws, CfnResource, Stack } from '@aws-cdk/core'; import { Test } from 'nodeunit'; import { EventBus } from '../lib'; @@ -170,6 +170,18 @@ export = { test.done(); }, + 'does not throw if eventBusName is a token'(test: Test) { + // GIVEN + const stack = new Stack(); + + // WHEN / THEN + test.doesNotThrow(() => new EventBus(stack, 'EventBus', { + eventBusName: Aws.STACK_NAME, + })); + + test.done(); + }, + 'event bus source name must follow pattern'(test: Test) { // GIVEN const stack = new Stack();