diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-events/test/integ.eventbus.js.snapshot/Stack.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-events/test/integ.eventbus.js.snapshot/Stack.assets.json index 7e02c8ce09ced..cd6099e293e32 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-events/test/integ.eventbus.js.snapshot/Stack.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-events/test/integ.eventbus.js.snapshot/Stack.assets.json @@ -1,7 +1,7 @@ { "version": "36.0.0", "files": { - "1ac02a396bc49bcce2ab3c276dd4e234efe7e86f9d1a06c9ae16c054f1764bf1": { + "2671a34b39f9d75f10baaa810e7901cbcaa8901ff9852aa7a49bf43a87af0155": { "source": { "path": "Stack.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "1ac02a396bc49bcce2ab3c276dd4e234efe7e86f9d1a06c9ae16c054f1764bf1.json", + "objectKey": "2671a34b39f9d75f10baaa810e7901cbcaa8901ff9852aa7a49bf43a87af0155.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-events/test/integ.eventbus.js.snapshot/Stack.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-events/test/integ.eventbus.js.snapshot/Stack.template.json index 0fc44e208d8ce..ec1b73099f571 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-events/test/integ.eventbus.js.snapshot/Stack.template.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-events/test/integ.eventbus.js.snapshot/Stack.template.json @@ -3,6 +3,7 @@ "BusEA82B648": { "Type": "AWS::Events::EventBus", "Properties": { + "Description": "myEventBus", "Name": "StackBusAA0A1E4B" } }, diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-events/test/integ.eventbus.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-events/test/integ.eventbus.js.snapshot/manifest.json index c943d4cd06dd7..48b493126292a 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-events/test/integ.eventbus.js.snapshot/manifest.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-events/test/integ.eventbus.js.snapshot/manifest.json @@ -18,7 +18,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/1ac02a396bc49bcce2ab3c276dd4e234efe7e86f9d1a06c9ae16c054f1764bf1.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/2671a34b39f9d75f10baaa810e7901cbcaa8901ff9852aa7a49bf43a87af0155.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -63,24 +63,6 @@ "type": "aws:cdk:logicalId", "data": "CheckBootstrapVersion" } - ], - "BusStatement1B4D0336C": [ - { - "type": "aws:cdk:logicalId", - "data": "BusStatement1B4D0336C", - "trace": [ - "!!DESTRUCTIVE_CHANGES: WILL_DESTROY" - ] - } - ], - "BusStatement2B5FB314B": [ - { - "type": "aws:cdk:logicalId", - "data": "BusStatement2B5FB314B", - "trace": [ - "!!DESTRUCTIVE_CHANGES: WILL_DESTROY" - ] - } ] }, "displayName": "Stack" diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-events/test/integ.eventbus.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-events/test/integ.eventbus.js.snapshot/tree.json index d1f3f70812aa6..70659c5fb56dd 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-events/test/integ.eventbus.js.snapshot/tree.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-events/test/integ.eventbus.js.snapshot/tree.json @@ -18,12 +18,13 @@ "attributes": { "aws:cdk:cloudformation:type": "AWS::Events::EventBus", "aws:cdk:cloudformation:props": { + "description": "myEventBus", "name": "StackBusAA0A1E4B" } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_events.CfnEventBus", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "cdk-Statement1": { @@ -72,14 +73,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_events.CfnEventBusPolicy", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_events.EventBusPolicy", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "cdk-Statement2": { @@ -128,42 +129,42 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_events.CfnEventBusPolicy", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_events.EventBusPolicy", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_events.EventBus", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "BootstrapVersion": { "id": "BootstrapVersion", "path": "Stack/BootstrapVersion", "constructInfo": { - "fqn": "aws-cdk-lib.CfnParameter", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "CheckBootstrapVersion": { "id": "CheckBootstrapVersion", "path": "Stack/CheckBootstrapVersion", "constructInfo": { - "fqn": "aws-cdk-lib.CfnRule", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.Stack", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "IntegTest-EventBusStack": { @@ -190,22 +191,22 @@ "id": "BootstrapVersion", "path": "IntegTest-EventBusStack/DefaultTest/DeployAssert/BootstrapVersion", "constructInfo": { - "fqn": "aws-cdk-lib.CfnParameter", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "CheckBootstrapVersion": { "id": "CheckBootstrapVersion", "path": "IntegTest-EventBusStack/DefaultTest/DeployAssert/CheckBootstrapVersion", "constructInfo": { - "fqn": "aws-cdk-lib.CfnRule", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.Stack", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, @@ -230,8 +231,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.App", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } } \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-events/test/integ.eventbus.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-events/test/integ.eventbus.ts index 08b54b635dd1b..c7ce9708f4094 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-events/test/integ.eventbus.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-events/test/integ.eventbus.ts @@ -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, diff --git a/packages/aws-cdk-lib/aws-events/README.md b/packages/aws-cdk-lib/aws-events/README.md index 0a9c871d4fddb..14e4ed01b8926 100644 --- a/packages/aws-cdk-lib/aws-events/README.md +++ b/packages/aws-cdk-lib/aws-events/README.md @@ -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', { diff --git a/packages/aws-cdk-lib/aws-events/lib/event-bus.ts b/packages/aws-cdk-lib/aws-events/lib/event-bus.ts index 6b164ceae7c84..4999351a625a3 100644 --- a/packages/aws-cdk-lib/aws-events/lib/event-bus.ts +++ b/packages/aws-cdk-lib/aws-events/lib/event-bus.ts @@ -80,6 +80,17 @@ export interface EventBusProps { */ readonly eventSourceName?: string; + /** + * The event bus description. + * + * The description can be up to 512 characters long. + * + * @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. * @@ -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) { + 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, }); diff --git a/packages/aws-cdk-lib/aws-events/test/event-bus.test.ts b/packages/aws-cdk-lib/aws-events/test/event-bus.test.ts index 7b2a034b64d58..0bfa70b3534aa 100644 --- a/packages/aws-cdk-lib/aws-events/test/event-bus.test.ts +++ b/packages/aws-cdk-lib/aws-events/test/event-bus.test.ts @@ -48,6 +48,21 @@ describe('event bus', () => { }); }); + test('event bus with description', () => { + // GIVEN + const stack = new Stack(); + + // WHEN + new EventBus(stack, 'myEventBus', { + description: 'myEventBusDescription', + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::Events::EventBus', { + Description: 'myEventBusDescription', + }); + }); + test('partner event bus', () => { // GIVEN const stack = new Stack(); @@ -281,6 +296,19 @@ describe('event bus', () => { }).toThrow(/'eventSourceName' must satisfy: /); }); + test('event bus description cannot be too long', () => { + // 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();