Skip to content
v2.273.0

S3EventSourceV2 Class ​

S3EventSourceV2 Use S3 bucket notifications as an event source for AWS Lambda.

Example ​

ts
import * as s3 from 'aws-cdk-lib/aws-s3';
import { S3EventSourceV2 } from 'aws-cdk-lib/aws-lambda-event-sources';

const bucket = s3.Bucket.fromBucketName(this, 'Bucket', 'amzn-s3-demo-bucket');
declare const fn: lambda.Function;

fn.addEventSource(new S3EventSourceV2(bucket, {
  events: [ s3.EventType.OBJECT_CREATED, s3.EventType.OBJECT_REMOVED ],
  filters: [ { prefix: 'subdir/' } ], // optional
}));
python
import aws_cdk.aws_s3 as s3
from aws_cdk.aws_lambda_event_sources import S3EventSourceV2
# fn: lambda.Function


bucket = s3.Bucket.from_bucket_name(self, "Bucket", "amzn-s3-demo-bucket")

fn.add_event_source(S3EventSourceV2(bucket,
    events=[s3.EventType.OBJECT_CREATED, s3.EventType.OBJECT_REMOVED],
    filters=[s3.NotificationKeyFilter(prefix="subdir/")]
))
java
import software.amazon.awscdk.services.s3.*;
import software.amazon.awscdk.services.lambda.eventsources.S3EventSourceV2;
Function fn;


IBucket bucket = Bucket.fromBucketName(this, "Bucket", "amzn-s3-demo-bucket");

fn.addEventSource(S3EventSourceV2.Builder.create(bucket)
        .events(List.of(EventType.OBJECT_CREATED, EventType.OBJECT_REMOVED))
        .filters(List.of(NotificationKeyFilter.builder().prefix("subdir/").build()))
        .build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.S3;
using Amazon.CDK.AWS.Lambda.EventSources;
Function fn;


var bucket = Bucket.FromBucketName(this, "Bucket", "amzn-s3-demo-bucket");

fn.AddEventSource(new S3EventSourceV2(bucket, new S3EventSourceProps {
    Events = new [] { EventType.OBJECT_CREATED, EventType.OBJECT_REMOVED },
    Filters = new [] { new NotificationKeyFilter { Prefix = "subdir/" } }
}));
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
var fn Function


bucket := s3.Bucket_FromBucketName(this, jsii.String("Bucket"), jsii.String("amzn-s3-demo-bucket"))

fn.AddEventSource(awscdk.NewS3EventSourceV2(bucket, &S3EventSourceProps{
	Events: []EventType{
		s3.EventType_OBJECT_CREATED,
		s3.EventType_OBJECT_REMOVED,
	},
	Filters: []NotificationKeyFilter{
		&NotificationKeyFilter{
			Prefix: jsii.String("subdir/"),
		},
	},
}))

Initializer ​

ts
new S3EventSourceV2(bucket: IBucket, props: S3EventSourceProps)
python
S3EventSourceV2(bucket: IBucket, props: S3EventSourceProps)
java
new S3EventSourceV2(IBucket bucket, S3EventSourceProps props)
csharp
new S3EventSourceV2(IBucket bucket, S3EventSourceProps props)
go
NewS3EventSourceV2(Bucket IBucket, Props S3EventSourceProps)

Methods ​

bind(target: IFunction): voiddef bind(self, target: IFunction) -> Nonepublic void bind(IFunction target)public void Bind(IFunction target)func Bind(Target IFunction)#
Called by `lambda.addEventSource` to allow the event source to bind to this function.