-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial work on bucket notifications
Remaining work: - [ ] Define a custom resource to break the cycle - [ ] Add `IBucketNotificationTarget` on SQS
- Loading branch information
Elad Ben-Israel
committed
Jun 30, 2018
1 parent
ae40183
commit 625aef4
Showing
14 changed files
with
572 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './bucket'; | ||
export * from './bucket-policy'; | ||
export * from './rule'; | ||
export * from './rule'; | ||
export * from './notifications'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import { Arn } from "@aws-cdk/core"; | ||
import { s3 } from '@aws-cdk/resources'; | ||
|
||
export enum EventType { | ||
/** | ||
* Amazon S3 APIs such as PUT, POST, and COPY can create an object. Using | ||
* these event types, you can enable notification when an object is created | ||
* using a specific API, or you can use the s3:ObjectCreated:* event type to | ||
* request notification regardless of the API that was used to create an | ||
* object. | ||
*/ | ||
ObjectCreated = 's3:ObjectCreated:*', | ||
|
||
/** | ||
* Amazon S3 APIs such as PUT, POST, and COPY can create an object. Using | ||
* these event types, you can enable notification when an object is created | ||
* using a specific API, or you can use the s3:ObjectCreated:* event type to | ||
* request notification regardless of the API that was used to create an | ||
* object. | ||
*/ | ||
ObjectCreatedPut = 's3:ObjectCreated:Put', | ||
|
||
/** | ||
* Amazon S3 APIs such as PUT, POST, and COPY can create an object. Using | ||
* these event types, you can enable notification when an object is created | ||
* using a specific API, or you can use the s3:ObjectCreated:* event type to | ||
* request notification regardless of the API that was used to create an | ||
* object. | ||
*/ | ||
ObjectCreatedPost = 's3:ObjectCreated:Post', | ||
|
||
/** | ||
* Amazon S3 APIs such as PUT, POST, and COPY can create an object. Using | ||
* these event types, you can enable notification when an object is created | ||
* using a specific API, or you can use the s3:ObjectCreated:* event type to | ||
* request notification regardless of the API that was used to create an | ||
* object. | ||
*/ | ||
ObjectCreatedCopy = 's3:ObjectCreated:Copy', | ||
|
||
/** | ||
* Amazon S3 APIs such as PUT, POST, and COPY can create an object. Using | ||
* these event types, you can enable notification when an object is created | ||
* using a specific API, or you can use the s3:ObjectCreated:* event type to | ||
* request notification regardless of the API that was used to create an | ||
* object. | ||
*/ | ||
ObjectCreatedCompleteMultipartUpload = 's3:ObjectCreated:CompleteMultipartUpload', | ||
|
||
/** | ||
* By using the ObjectRemoved event types, you can enable notification when | ||
* an object or a batch of objects is removed from a bucket. | ||
* | ||
* You can request notification when an object is deleted or a versioned | ||
* object is permanently deleted by using the s3:ObjectRemoved:Delete event | ||
* type. Or you can request notification when a delete marker is created for | ||
* a versioned object by using s3:ObjectRemoved:DeleteMarkerCreated. For | ||
* information about deleting versioned objects, see Deleting Object | ||
* Versions. You can also use a wildcard s3:ObjectRemoved:* to request | ||
* notification anytime an object is deleted. | ||
* | ||
* You will not receive event notifications from automatic deletes from | ||
* lifecycle policies or from failed operations. | ||
*/ | ||
ObjectRemoved = 's3:ObjectRemoved:*', | ||
|
||
/** | ||
* By using the ObjectRemoved event types, you can enable notification when | ||
* an object or a batch of objects is removed from a bucket. | ||
* | ||
* You can request notification when an object is deleted or a versioned | ||
* object is permanently deleted by using the s3:ObjectRemoved:Delete event | ||
* type. Or you can request notification when a delete marker is created for | ||
* a versioned object by using s3:ObjectRemoved:DeleteMarkerCreated. For | ||
* information about deleting versioned objects, see Deleting Object | ||
* Versions. You can also use a wildcard s3:ObjectRemoved:* to request | ||
* notification anytime an object is deleted. | ||
* | ||
* You will not receive event notifications from automatic deletes from | ||
* lifecycle policies or from failed operations. | ||
*/ | ||
ObjectRemovedDelete = 's3:ObjectRemoved:Delete', | ||
|
||
/** | ||
* By using the ObjectRemoved event types, you can enable notification when | ||
* an object or a batch of objects is removed from a bucket. | ||
* | ||
* You can request notification when an object is deleted or a versioned | ||
* object is permanently deleted by using the s3:ObjectRemoved:Delete event | ||
* type. Or you can request notification when a delete marker is created for | ||
* a versioned object by using s3:ObjectRemoved:DeleteMarkerCreated. For | ||
* information about deleting versioned objects, see Deleting Object | ||
* Versions. You can also use a wildcard s3:ObjectRemoved:* to request | ||
* notification anytime an object is deleted. | ||
* | ||
* You will not receive event notifications from automatic deletes from | ||
* lifecycle policies or from failed operations. | ||
*/ | ||
ObjectRemovedDeleteMarkerCreated = 's3:ObjectRemoved:DeleteMarkerCreated', | ||
|
||
/** | ||
* 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. | ||
*/ | ||
ReducedRedundancyLostObject = 's3:ReducedRedundancyLostObject', | ||
} | ||
|
||
export interface BucketNotificationProps { | ||
/** | ||
* The S3 bucket event. | ||
*/ | ||
event: EventType; | ||
|
||
/** | ||
* The filtering rule that determine which objects trigger the event. For | ||
* example, you can create a filter so that only image files with a .jpg | ||
* extension trigger the event when they are added to the S3 bucket. | ||
* | ||
* @default All objects will trigger the event | ||
*/ | ||
s3KeyFilter?: string; | ||
|
||
/** | ||
* The target of the notification. | ||
*/ | ||
target: IBucketNotificationTarget; | ||
} | ||
|
||
export interface IBucketNotificationTarget { | ||
bucketNotificationTarget(bucketArn: s3.BucketArn): BucketNotificationTarget; | ||
} | ||
|
||
export interface BucketNotificationTarget { | ||
readonly type: BucketNotificationTargetType; | ||
readonly arn: Arn; | ||
} | ||
|
||
export enum BucketNotificationTargetType { | ||
Lambda, | ||
Queue, | ||
Topic | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,4 +157,4 @@ | |
} | ||
} | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
packages/@aws-cdk/s3/test/integ.notifications.expected.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"Resources": { | ||
"TestBucket560B80BC": { | ||
"Type": "AWS::S3::Bucket", | ||
"Properties": { | ||
"NotificationConfiguration": { | ||
"TopicConfigurations": [ | ||
{ | ||
"Event": "s3:ObjectCreated:*", | ||
"Filter": { | ||
"S3Key": { | ||
"Rules": [ | ||
{ | ||
"Name": "prefix", | ||
"Value": "images/" | ||
}, | ||
{ | ||
"Name": "suffix", | ||
"Value": ".jpg" | ||
} | ||
] | ||
} | ||
}, | ||
"Topic": { | ||
"Ref": "Topic" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"Topic": { | ||
"Type": "AWS::SNS::Topic" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { App, Resource, Stack } from '@aws-cdk/core'; | ||
import { Bucket, EventType, BucketNotificationTargetType } from '../lib'; | ||
|
||
const app = new App(process.argv); | ||
|
||
const stack = new Stack(app, 'aws-cdk-s3-bucket-notifications'); | ||
|
||
const bucket = new Bucket(stack, 'TestBucket'); | ||
|
||
const topic = new Resource(stack, 'Topic', { | ||
type: 'AWS::SNS::Topic' | ||
}); | ||
|
||
const bucketNotificationTarget = { | ||
type: BucketNotificationTargetType.Topic, | ||
arn: topic.ref | ||
}; | ||
|
||
bucket.onEvent(EventType.ObjectCreated, { bucketNotificationTarget }, 'images/*', '*.jpg'); | ||
|
||
process.stdout.write(app.run()); |
Oops, something went wrong.