Commit 073185d
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- packages
- @aws-cdk/mixins-preview
- lib/services
- aws-athena
- aws-autoscaling
- aws-cloudwatch
- aws-codecommit
- aws-connect
- aws-ec2
- aws-ecr
- aws-ecs
- aws-glue
- aws-guardduty
- aws-healthimaging
- aws-iotanalytics
- aws-kms
- aws-logs
- aws-medialive
- aws-mediapackage
- aws-networkmanager
- aws-omics
- aws-opsworks
- aws-organizations
- aws-route53recoveryreadiness
- aws-route53resolver
- aws-s3
- aws-transfer
- aws-voiceid
- aws-workspaces
- rosetta
- scripts
- spec2eventbridge
- spec2mixins
- test/events
- aws-cdk-lib/core/lib
- tools/@aws-cdk/spec2cdk
- lib
- cdk
- naming
- util
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| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
0 commit comments