aws-cdk-lib.aws_s3_notifications-readme

aws-cdk-lib.aws_s3_notifications module

LanguagePackage
.NETAmazon.CDK.AWS.S3.Notifications
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awss3notifications
Javasoftware.amazon.awscdk.services.s3.notifications
Pythonaws_cdk.aws_s3_notifications
TypeScriptaws-cdk-lib » aws_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 * as sns from 'aws-cdk-lib/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));

Example not in your language?

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

import * as sqs from 'aws-cdk-lib/aws-sqs';

const bucket = new s3.Bucket(this, 'Bucket');
const queue = new sqs.Queue(this, 'Queue');

bucket.addEventNotification(s3.EventType.OBJECT_CREATED_PUT, new s3n.SqsDestination(queue));

Example not in your language?

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-lib/aws-lambda';

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

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

Example not in your language?