Skip to content

Commit 073185d

Browse files
authored
feat: helpers to generate EventBridge event patterns for 26 services (#36121)
### Issue # (if applicable) Closes #<issue number here>. ### Reason for this change This PR automatically generates EventBridge Event Pattern based on the information coming from the `awscdk-service-spec`. This enables this kind of functionality: ``` const bucket = new s3.Bucket(stack, 'Bucket'); const bucketEvents = BucketEvents.fromBucket(bucket); new events.Rule(stack, 'Rule', { eventPattern: bucketEvents.objectCreatedPattern({ object: { key: ['uploads/*'] } }), targets: [new targets.LambdaFunction(fn)] }); ``` ### Description of changes This PR introduces a new code generator for `events` to create the following generated code: ``` export class ResourceEvents { public static fromResource(workspaceRef: service.IResourceRef): ResourceEvents { return new ResourceEvents(workspaceRef); } private readonly workspaceRef: service.IResourceRef; private constructor(workspaceRef: service.IResourceRef) { this.workspaceRef = workspaceRef; } public resourceAccessPattern(options?: ResourceEvents.RessourceAccess.PatternProps): events.EventPattern { const { eventMetadata, ...obj } = (options || {}); return { source: ["aws.service"], detailType: ["Resource Access"], detail: convertWorkSpacesAccessDetailToEventPattern(obj, this.workspaceRef), version: eventMetadata?.version, resources: eventMetadata?.resources, region: eventMetadata?.region }; } } export namespace ResourceEvents { export class RessourceAccess { } export namespace RessourceAccess { export interface RessourceAccessDetail { readonly myProp?: Array<string>; readonly resourceId?: Array<string>; } export interface PatternProps extends ResourceEvents.ResourceAccess.ResourceAccessDetail { readonly eventMetadata?: cdk.AWSEventMetadataProps; } } } // @ts-ignore TS6133 function convertWorkSpacesAccessDetailToEventPattern(obj?: ResourceEvents.WorkSpacesAccess.WorkSpacesAccessDetail, iRef: service.IResourceRef): any { const ret = ({ myProp: obj?.myProp, resourceId: (obj?.workspaceId ?? [iRef.resourceRef.resourceId]) } as any); for (const [key, value] of Object.entries(ret)) { if ((value === undefined)) delete ret[key]; } if (Object.keys(ret).length === 0) return undefined;; return ret; } ``` ### Describe any new or updated permissions being added ### Description of how you validated changes - Added unit tests - Tested real world functionality by deploying stacks using this new functionality, integ tests will follow ### 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 9b337df commit 073185d

File tree

71 files changed

+1087
-15
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1087
-15
lines changed

packages/@aws-cdk/mixins-preview/README.md

Lines changed: 104 additions & 9 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"exclude": [
3+
"props-default-doc:*"
4+
]
5+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './events.generated';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
export * as events from './events';
12
export * as mixins from './mixins';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './events.generated';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
export * as events from './events';
12
export * as mixins from './mixins';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './events.generated';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
export * as events from './events';
12
export * as mixins from './mixins';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './events.generated';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
export * as events from './events';
12
export * as mixins from './mixins';

0 commit comments

Comments
 (0)