From ee0db39109824d3a511372c3337e0812e7a5fee9 Mon Sep 17 00:00:00 2001 From: Ross Date: Wed, 30 Sep 2020 00:16:01 +0100 Subject: [PATCH] feat(s3): support replication and restore s3 notification event types (#10552) Adding support for [additional S3 notification event types](https://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html#supported-notification-event-types), including 's3:ObjectRestore:Completed' recently raised by @mauricioharley as a feature request. Closes #10498 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- packages/@aws-cdk/aws-s3/lib/bucket.ts | 51 ++++++++++++++++++- .../@aws-cdk/aws-s3/test/test.notification.ts | 15 +++++- 2 files changed, 62 insertions(+), 4 deletions(-) diff --git a/packages/@aws-cdk/aws-s3/lib/bucket.ts b/packages/@aws-cdk/aws-s3/lib/bucket.ts index 99ecca8402211..1e2357c4d840c 100644 --- a/packages/@aws-cdk/aws-s3/lib/bucket.ts +++ b/packages/@aws-cdk/aws-s3/lib/bucket.ts @@ -1322,7 +1322,7 @@ export class Bucket extends BucketBase { } /** - * Subscribes a destination to receive notificatins when an object is + * Subscribes a destination to receive notifications when an object is * created in the bucket. This is identical to calling * `onEvent(EventType.ObjectCreated)`. * @@ -1334,7 +1334,7 @@ export class Bucket extends BucketBase { } /** - * Subscribes a destination to receive notificatins when an object is + * Subscribes a destination to receive notifications when an object is * removed from the bucket. This is identical to calling * `onEvent(EventType.ObjectRemoved)`. * @@ -1782,12 +1782,59 @@ export enum EventType { */ OBJECT_REMOVED_DELETE_MARKER_CREATED = 's3:ObjectRemoved:DeleteMarkerCreated', + /** + * Using restore object event types you can receive notifications for + * initiation and completion when restoring objects from the S3 Glacier + * storage class. + * + * You use s3:ObjectRestore:Post to request notification of object restoration + * initiation. + */ + OBJECT_RESTORE_POST = 's3:ObjectRestore:Post', + + /** + * Using restore object event types you can receive notifications for + * initiation and completion when restoring objects from the S3 Glacier + * storage class. + * + * You use s3:ObjectRestore:Completed to request notification of + * restoration completion. + */ + OBJECT_RESTORE_COMPLETED = 's3:ObjectRestore:Completed', + /** * You can use this event type to request Amazon S3 to send a notification * message when Amazon S3 detects that an object of the RRS storage class is * lost. */ REDUCED_REDUNDANCY_LOST_OBJECT = 's3:ReducedRedundancyLostObject', + + /** + * You receive this notification event when an object that was eligible for + * replication using Amazon S3 Replication Time Control failed to replicate. + */ + REPLICATION_OPERATION_FAILED_REPLICATION = 's3:Replication:OperationFailedReplication', + + /** + * You receive this notification event when an object that was eligible for + * replication using Amazon S3 Replication Time Control exceeded the 15-minute + * threshold for replication. + */ + REPLICATION_OPERATION_MISSED_THRESHOLD = 's3:Replication:OperationMissedThreshold', + + /** + * You receive this notification event for an object that was eligible for + * replication using the Amazon S3 Replication Time Control feature replicated + * after the 15-minute threshold. + */ + REPLICATION_OPERATION_REPLICATED_AFTER_THRESHOLD = 's3:Replication:OperationReplicatedAfterThreshold', + + /** + * You receive this notification event for an object that was eligible for + * replication using Amazon S3 Replication Time Control but is no longer tracked + * by replication metrics. + */ + REPLICATION_OPERATION_NOT_TRACKED = 's3:Replication:OperationNotTracked', } export interface NotificationKeyFilter { diff --git a/packages/@aws-cdk/aws-s3/test/test.notification.ts b/packages/@aws-cdk/aws-s3/test/test.notification.ts index 90107f917f375..1eb3708dc10c5 100644 --- a/packages/@aws-cdk/aws-s3/test/test.notification.ts +++ b/packages/@aws-cdk/aws-s3/test/test.notification.ts @@ -4,7 +4,7 @@ import { Test } from 'nodeunit'; import * as s3 from '../lib'; export = { - 'when notification are added, a custom resource is provisioned + a lambda handler for it'(test: Test) { + 'when notification is added a custom s3 bucket notification resource is provisioned'(test: Test) { const stack = new cdk.Stack(); const bucket = new s3.Bucket(stack, 'MyBucket'); @@ -17,7 +17,18 @@ export = { }); expect(stack).to(haveResource('AWS::S3::Bucket')); - expect(stack).to(haveResource('Custom::S3BucketNotifications')); + expect(stack).to(haveResource('Custom::S3BucketNotifications', { + NotificationConfiguration: { + TopicConfigurations: [ + { + Events: [ + 's3:ObjectCreated:*', + ], + TopicArn: 'ARN', + }, + ], + }, + })); test.done(); },