Package software.amazon.awscdk.services.s3.notifications


package software.amazon.awscdk.services.s3.notifications

S3 Bucket Notifications Destinations

This module includes integration classes for using Topics, Queues or Lambdas as S3 Notification Destinations.

Examples

The following example shows how to send a notification to an SNS topic when an object is created in an S3 bucket:

 import software.amazon.awscdk.services.sns.*;
 
 
 Bucket bucket = new Bucket(this, "Bucket");
 Topic topic = new Topic(this, "Topic");
 
 bucket.addEventNotification(EventType.OBJECT_CREATED_PUT, new SnsDestination(topic));
 

The following example shows how to send a notification to an SQS queue when an object is created in an S3 bucket:

 import software.amazon.awscdk.services.sqs.*;
 
 
 Bucket bucket = new Bucket(this, "Bucket");
 Queue queue = new Queue(this, "Queue");
 
 bucket.addEventNotification(EventType.OBJECT_CREATED_PUT, new SqsDestination(queue));
 

The following example shows how to send a notification to a Lambda function when an object is created in an S3 bucket:

 import software.amazon.awscdk.services.lambda.*;
 
 
 Bucket bucket = new Bucket(this, "Bucket");
 Function fn = Function.Builder.create(this, "MyFunction")
         .runtime(Runtime.NODEJS_LATEST)
         .handler("index.handler")
         .code(Code.fromAsset(join(__dirname, "lambda-handler")))
         .build();
 
 bucket.addEventNotification(EventType.OBJECT_CREATED, new LambdaDestination(fn));