Skip to content

Commit

Permalink
fix(events): cannot use tokens as event bus name (aws#10772)
Browse files Browse the repository at this point in the history
added a condition to ensure that eventBusName does not contain
an unresolved token before performing validation.

Closes aws#10467


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
shivlaks authored Oct 7, 2020
1 parent 08efc96 commit 8bee193
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-events/lib/event-bus.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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\'',
Expand Down
14 changes: 13 additions & 1 deletion packages/@aws-cdk/aws-events/test/test.event-bus.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 8bee193

Please sign in to comment.