From 684812bc17a172a515a7e12b4a23a8699d0684ca Mon Sep 17 00:00:00 2001 From: yuppe Date: Wed, 24 Jul 2024 12:25:44 +0900 Subject: [PATCH 1/4] feat(events): add property for --- .../Stack.assets.json | 4 +- .../Stack.template.json | 1 + .../integ.eventbus.js.snapshot/manifest.json | 20 +------ .../test/integ.eventbus.js.snapshot/tree.json | 53 ++++++++++--------- .../test/aws-events/test/integ.eventbus.ts | 4 +- packages/aws-cdk-lib/aws-events/README.md | 3 +- .../aws-cdk-lib/aws-events/lib/event-bus.ts | 16 ++++++ .../aws-events/test/event-bus.test.ts | 15 ++++++ 8 files changed, 67 insertions(+), 49 deletions(-) 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..6609d13fe9383 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 must be maximum 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..f2661520fe1d5 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 @@ -40,11 +40,13 @@ describe('event bus', () => { // WHEN new EventBus(stack, 'Bus', { eventBusName: 'myEventBus', + description: 'myEventBus', }); // THEN Template.fromStack(stack).hasResourceProperties('AWS::Events::EventBus', { Name: 'myEventBus', + Description: 'myEventBus', }); }); @@ -281,6 +283,19 @@ describe('event bus', () => { }).toThrow(/'eventSourceName' must satisfy: /); }); + test('throw error when versionDescription is 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(); From ce563e9c3454c779cdc682dd0358064349a1f3d8 Mon Sep 17 00:00:00 2001 From: yuppe Date: Wed, 24 Jul 2024 12:32:16 +0900 Subject: [PATCH 2/4] fix: inappropriate test case name --- packages/aws-cdk-lib/aws-events/test/event-bus.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f2661520fe1d5..b394f1c14644e 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 @@ -283,7 +283,7 @@ describe('event bus', () => { }).toThrow(/'eventSourceName' must satisfy: /); }); - test('throw error when versionDescription is too long', () => { + test('throw error when description is too long', () => { // GIVEN const stack = new Stack(); const tooLongDescription = 'a'.repeat(513); From 0b9a67e027d4f8f8ec129ac887637dc466fb9dd8 Mon Sep 17 00:00:00 2001 From: yuppe Date: Thu, 25 Jul 2024 11:34:25 +0900 Subject: [PATCH 3/4] fix: divide test into the right level of detail --- .../aws-events/test/event-bus.test.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) 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 b394f1c14644e..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 @@ -40,13 +40,26 @@ describe('event bus', () => { // WHEN new EventBus(stack, 'Bus', { eventBusName: 'myEventBus', - description: 'myEventBus', }); // THEN Template.fromStack(stack).hasResourceProperties('AWS::Events::EventBus', { Name: 'myEventBus', - Description: 'myEventBus', + }); + }); + + 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', }); }); @@ -283,7 +296,7 @@ describe('event bus', () => { }).toThrow(/'eventSourceName' must satisfy: /); }); - test('throw error when description is too long', () => { + test('event bus description cannot be too long', () => { // GIVEN const stack = new Stack(); const tooLongDescription = 'a'.repeat(513); From da57c04e741aba6634154465038a7e108c29836c Mon Sep 17 00:00:00 2001 From: Kendra Neil <53584728+TheRealAmazonKendra@users.noreply.github.com> Date: Wed, 31 Jul 2024 10:43:20 -0700 Subject: [PATCH 4/4] Update packages/aws-cdk-lib/aws-events/lib/event-bus.ts Co-authored-by: Leonardo Gama <51037424+Leo10Gama@users.noreply.github.com> --- packages/aws-cdk-lib/aws-events/lib/event-bus.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 6609d13fe9383..4999351a625a3 100644 --- a/packages/aws-cdk-lib/aws-events/lib/event-bus.ts +++ b/packages/aws-cdk-lib/aws-events/lib/event-bus.ts @@ -83,7 +83,7 @@ export interface EventBusProps { /** * The event bus description. * - * The description must be maximum 512 characters long. + * 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 *