Skip to content

Commit

Permalink
fix(events): PhysicalName.GENERATE_IF_NEEDED does not work for EventB…
Browse files Browse the repository at this point in the history
…us (#17008)

fixes an issue where the generate when needed marker was not being
passed through to the physicalName

fix #14337


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
corymhall committed Oct 19, 2021
1 parent d1cee62 commit 707fa00
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/@aws-cdk/aws-events/lib/event-bus.ts
Expand Up @@ -276,6 +276,8 @@ export class EventBus extends EventBusBase {
);
}
return { eventBusName: eventSourceName, eventSourceName };
} else {
return { eventBusName: props.eventBusName };
}
}
return { eventBusName: defaultEventBusName };
Expand Down Expand Up @@ -311,7 +313,7 @@ export class EventBus extends EventBusBase {
super(scope, id, { physicalName: eventBusName });

const eventBus = new CfnEventBus(this, 'Resource', {
name: eventBusName,
name: this.physicalName,
eventSourceName,
});

Expand Down
30 changes: 29 additions & 1 deletion packages/@aws-cdk/aws-events/test/event-bus.test.ts
@@ -1,6 +1,6 @@
import '@aws-cdk/assert-internal/jest';
import * as iam from '@aws-cdk/aws-iam';
import { Aws, CfnResource, Stack, Arn } from '@aws-cdk/core';
import { Aws, CfnResource, Stack, Arn, App, PhysicalName, CfnOutput } from '@aws-cdk/core';
import { EventBus } from '../lib';

describe('event bus', () => {
Expand Down Expand Up @@ -515,4 +515,32 @@ describe('event bus', () => {


});
test('cross account event bus uses generated physical name', () => {
// GIVEN
const app = new App();
const stack1 = new Stack(app, 'Stack1', {
env: {
account: '11111111111',
region: 'us-east-1',
},
});
const stack2 = new Stack(app, 'Stack2', {
env: {
account: '22222222222',
region: 'us-east-1',
},
});

// WHEN
const bus1 = new EventBus(stack1, 'Bus', {
eventBusName: PhysicalName.GENERATE_IF_NEEDED,
});

new CfnOutput(stack2, 'BusName', { value: bus1.eventBusName });

// THEN
expect(stack1).toHaveResource('AWS::Events::EventBus', {
Name: 'stack1stack1busca19bdf8ab2e51b62a5a',
});
});
});

0 comments on commit 707fa00

Please sign in to comment.