Skip to content

Commit 28fbc82

Browse files
authoredJul 31, 2024
feat(events): add description property for eventBus (#30935)
### Issue # (if applicable) N/A ### Reason for this change The change introduces the `description` property to the `EventBus` ### Description of changes - Add the `description` property for `EventBusProps`, which was missing in the L2 construct. - Add validation for character limit ### Description of how you validated changes I Added a unit test for eventBus and added the `description` property in the integration tests. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent fbc28bc commit 28fbc82

File tree

8 files changed

+80
-49
lines changed

8 files changed

+80
-49
lines changed
 

‎packages/@aws-cdk-testing/framework-integ/test/aws-events/test/integ.eventbus.js.snapshot/Stack.assets.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/@aws-cdk-testing/framework-integ/test/aws-events/test/integ.eventbus.js.snapshot/Stack.template.json

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"BusEA82B648": {
44
"Type": "AWS::Events::EventBus",
55
"Properties": {
6+
"Description": "myEventBus",
67
"Name": "StackBusAA0A1E4B"
78
}
89
},

‎packages/@aws-cdk-testing/framework-integ/test/aws-events/test/integ.eventbus.js.snapshot/manifest.json

+1-19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/@aws-cdk-testing/framework-integ/test/aws-events/test/integ.eventbus.js.snapshot/tree.json

+27-26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/@aws-cdk-testing/framework-integ/test/aws-events/test/integ.eventbus.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import { EventBus } from 'aws-cdk-lib/aws-events';
55

66
const app = new App();
77
const stack = new Stack(app, 'Stack');
8-
const bus = new EventBus(stack, 'Bus');
8+
const bus = new EventBus(stack, 'Bus', {
9+
description: 'myEventBus',
10+
});
911

1012
bus.addToResourcePolicy(new iam.PolicyStatement({
1113
effect: iam.Effect.ALLOW,

‎packages/aws-cdk-lib/aws-events/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ It is possible to archive all or some events sent to an event bus. It is then po
208208

209209
```ts
210210
const bus = new events.EventBus(this, 'bus', {
211-
eventBusName: 'MyCustomEventBus'
211+
eventBusName: 'MyCustomEventBus',
212+
description: 'MyCustomEventBus',
212213
});
213214

214215
bus.archive('MyArchive', {

‎packages/aws-cdk-lib/aws-events/lib/event-bus.ts

+16
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ export interface EventBusProps {
8080
*/
8181
readonly eventSourceName?: string;
8282

83+
/**
84+
* The event bus description.
85+
*
86+
* The description can be up to 512 characters long.
87+
*
88+
* @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-eventbus.html#cfn-events-eventbus-description
89+
*
90+
* @default - no description
91+
*/
92+
readonly description?: string;
93+
8394
/**
8495
* The customer managed key that encrypt events on this event bus.
8596
*
@@ -325,9 +336,14 @@ export class EventBus extends EventBusBase {
325336

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

339+
if (props?.description && !Token.isUnresolved(props.description) && props.description.length > 512) {
340+
throw new Error(`description must be less than or equal to 512 characters, got ${props.description.length}`);
341+
}
342+
328343
const eventBus = new CfnEventBus(this, 'Resource', {
329344
name: this.physicalName,
330345
eventSourceName,
346+
description: props?.description,
331347
kmsKeyIdentifier: props?.kmsKey?.keyArn,
332348
});
333349

‎packages/aws-cdk-lib/aws-events/test/event-bus.test.ts

+28
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,21 @@ describe('event bus', () => {
4848
});
4949
});
5050

51+
test('event bus with description', () => {
52+
// GIVEN
53+
const stack = new Stack();
54+
55+
// WHEN
56+
new EventBus(stack, 'myEventBus', {
57+
description: 'myEventBusDescription',
58+
});
59+
60+
// THEN
61+
Template.fromStack(stack).hasResourceProperties('AWS::Events::EventBus', {
62+
Description: 'myEventBusDescription',
63+
});
64+
});
65+
5166
test('partner event bus', () => {
5267
// GIVEN
5368
const stack = new Stack();
@@ -281,6 +296,19 @@ describe('event bus', () => {
281296
}).toThrow(/'eventSourceName' must satisfy: /);
282297
});
283298

299+
test('event bus description cannot be too long', () => {
300+
// GIVEN
301+
const stack = new Stack();
302+
const tooLongDescription = 'a'.repeat(513);
303+
304+
// WHEN / THEN
305+
expect(() => {
306+
new EventBus(stack, 'EventBusWithTooLongDescription', {
307+
description: tooLongDescription,
308+
});
309+
}).toThrow('description must be less than or equal to 512 characters, got 513');
310+
});
311+
284312
testDeprecated('can grant PutEvents', () => {
285313
// GIVEN
286314
const stack = new Stack();

0 commit comments

Comments
 (0)