Skip navigation links

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

S3 Bucket Notifications Destinations

See: Description

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

S3 Bucket Notifications Destinations

---

cdk-constructs: Stable


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_14_X)
         .handler("index.handler")
         .code(Code.fromAsset(join(__dirname, "lambda-handler")))
         .build();
 
 bucket.addEventNotification(EventType.OBJECT_CREATED, new LambdaDestination(fn));
 
Skip navigation links