Skip to content

Commit b0b7a32

Browse files
authored
feat(s3): Event Bridge notification can be enabled after the bucket is created (#20913)
Make `enableEventBridgeNotification()` public and available in `IBucket`. Unmanaged buckets can also have the notification enabled. Fixes #20824. ---- ### All Submissions: * [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 6b4f92f commit b0b7a32

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

packages/@aws-cdk/aws-s3/lib/bucket.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,23 @@ export interface IBucket extends IResource {
353353
* @param filters Filters (see onEvent)
354354
*/
355355
addObjectRemovedNotification(dest: IBucketNotificationDestination, ...filters: NotificationKeyFilter[]): void;
356+
357+
358+
/**
359+
* Enables event bridge notification, causing all events below to be sent to EventBridge:
360+
*
361+
* - Object Deleted (DeleteObject)
362+
* - Object Deleted (Lifecycle expiration)
363+
* - Object Restore Initiated
364+
* - Object Restore Completed
365+
* - Object Restore Expired
366+
* - Object Storage Class Changed
367+
* - Object Access Tier Changed
368+
* - Object ACL Updated
369+
* - Object Tags Added
370+
* - Object Tags Deleted
371+
*/
372+
enableEventBridgeNotification(): void;
356373
}
357374

358375
/**
@@ -874,7 +891,21 @@ export abstract class BucketBase extends Resource implements IBucket {
874891
return this.addEventNotification(EventType.OBJECT_REMOVED, dest, ...filters);
875892
}
876893

877-
protected enableEventBridgeNotification() {
894+
/**
895+
* Enables event bridge notification, causing all events below to be sent to EventBridge:
896+
*
897+
* - Object Deleted (DeleteObject)
898+
* - Object Deleted (Lifecycle expiration)
899+
* - Object Restore Initiated
900+
* - Object Restore Completed
901+
* - Object Restore Expired
902+
* - Object Storage Class Changed
903+
* - Object Access Tier Changed
904+
* - Object ACL Updated
905+
* - Object Tags Added
906+
* - Object Tags Deleted
907+
*/
908+
public enableEventBridgeNotification() {
878909
this.withNotifications(notifications => notifications.enableEventBridgeNotification());
879910
}
880911

packages/@aws-cdk/aws-s3/test/bucket.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2743,4 +2743,16 @@ describe('bucket', () => {
27432743
},
27442744
});
27452745
});
2746+
2747+
test('Event Bridge notification can be enabled after the bucket is created', () => {
2748+
const stack = new cdk.Stack();
2749+
const bucket = new s3.Bucket(stack, 'MyBucket');
2750+
bucket.enableEventBridgeNotification();
2751+
2752+
Template.fromStack(stack).hasResourceProperties('Custom::S3BucketNotifications', {
2753+
NotificationConfiguration: {
2754+
EventBridgeConfiguration: {},
2755+
},
2756+
});
2757+
});
27462758
});

0 commit comments

Comments
 (0)