@aws-cdk/aws-s3-notifications

Bucket Notifications API for AWS S3

Usage no npm install needed!

<script type="module">
  import awsCdkAwsS3Notifications from 'https://cdn.skypack.dev/@aws-cdk/aws-s3-notifications';
</script>

README

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 * as sns from '@aws-cdk/aws-sns';

const bucket = new s3.Bucket(this, 'Bucket');
const topic = new sns.Topic(this, 'Topic');

bucket.addEventNotification(s3.EventType.OBJECT_CREATED_PUT, new s3n.SnsDestination(topic));

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

import * as lambda from '@aws-cdk/aws-lambda';

const bucket = new s3.Bucket(this, 'Bucket');
const fn = new lambda.Function(this, 'MyFunction', {
  runtime: lambda.Runtime.NODEJS_12_X,
  handler: 'index.handler',
  code: lambda.Code.fromAsset(path.join(__dirname, 'lambda-handler')),
});

bucket.addEventNotification(s3.EventType.OBJECT_CREATED, new s3n.LambdaDestination(fn));