Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(events): add description property for eventBus #30935

Merged
merged 6 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"BusEA82B648": {
"Type": "AWS::Events::EventBus",
"Properties": {
"Description": "myEventBus",
"Name": "StackBusAA0A1E4B"
}
},
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { EventBus } from 'aws-cdk-lib/aws-events';

const app = new App();
const stack = new Stack(app, 'Stack');
const bus = new EventBus(stack, 'Bus');
const bus = new EventBus(stack, 'Bus', {
description: 'myEventBus',
});

bus.addToResourcePolicy(new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
Expand Down
3 changes: 2 additions & 1 deletion packages/aws-cdk-lib/aws-events/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ It is possible to archive all or some events sent to an event bus. It is then po

```ts
const bus = new events.EventBus(this, 'bus', {
eventBusName: 'MyCustomEventBus'
eventBusName: 'MyCustomEventBus',
description: 'MyCustomEventBus',
});

bus.archive('MyArchive', {
Expand Down
16 changes: 16 additions & 0 deletions packages/aws-cdk-lib/aws-events/lib/event-bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ export interface EventBusProps {
*/
readonly eventSourceName?: string;

/**
* The event bus description.
*
* The description must be maximum 512 characters long.
TheRealAmazonKendra marked this conversation as resolved.
Show resolved Hide resolved
*
* @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-eventbus.html#cfn-events-eventbus-description
*
* @default - no description
*/
readonly description?: string;

/**
* The customer managed key that encrypt events on this event bus.
*
Expand Down Expand Up @@ -325,9 +336,14 @@ export class EventBus extends EventBusBase {

super(scope, id, { physicalName: eventBusName });

if (props?.description && !Token.isUnresolved(props.description) && props.description.length > 512) {
Leo10Gama marked this conversation as resolved.
Show resolved Hide resolved
throw new Error(`description must be less than or equal to 512 characters, got ${props.description.length}`);
}

const eventBus = new CfnEventBus(this, 'Resource', {
name: this.physicalName,
eventSourceName,
description: props?.description,
kmsKeyIdentifier: props?.kmsKey?.keyArn,
});

Expand Down
15 changes: 15 additions & 0 deletions packages/aws-cdk-lib/aws-events/test/event-bus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ describe('event bus', () => {
// WHEN
new EventBus(stack, 'Bus', {
eventBusName: 'myEventBus',
description: 'myEventBus',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you separate it and create a new test because the name of this test is 'named event bus'?

});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Events::EventBus', {
Name: 'myEventBus',
Description: 'myEventBus',
});
});

Expand Down Expand Up @@ -281,6 +283,19 @@ describe('event bus', () => {
}).toThrow(/'eventSourceName' must satisfy: /);
});

test('throw error when description is too long', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually this test name is fine, but in this file, many tests for other errors have names of the following form: 'event bus xx cannot ...', so could you please match them?

// GIVEN
const stack = new Stack();
const tooLongDescription = 'a'.repeat(513);

// WHEN / THEN
expect(() => {
new EventBus(stack, 'EventBusWithTooLongDescription', {
description: tooLongDescription,
});
}).toThrow('description must be less than or equal to 512 characters, got 513');
});

testDeprecated('can grant PutEvents', () => {
// GIVEN
const stack = new Stack();
Expand Down
Loading