Skip to content
v2.275.0

SnsEventSource Class ​

Use an Amazon SNS topic as an event source for AWS Lambda.

Example ​

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

declare const topic: sns.Topic;
const deadLetterQueue = new sqs.Queue(this, 'deadLetterQueue');

declare const fn: lambda.Function;
fn.addEventSource(new SnsEventSource(topic, {
  filterPolicy: { },
  deadLetterQueue: deadLetterQueue,
}));
python
import aws_cdk.aws_sns as sns
from aws_cdk.aws_lambda_event_sources import SnsEventSource

# topic: sns.Topic

# fn: lambda.Function

dead_letter_queue = sqs.Queue(self, "deadLetterQueue")
fn.add_event_source(SnsEventSource(topic,
    filter_policy={},
    dead_letter_queue=dead_letter_queue
))
java
import software.amazon.awscdk.services.sns.*;
import software.amazon.awscdk.services.lambda.eventsources.SnsEventSource;

Topic topic;

Function fn;

Queue deadLetterQueue = new Queue(this, "deadLetterQueue");
fn.addEventSource(SnsEventSource.Builder.create(topic)
        .filterPolicy(Map.of())
        .deadLetterQueue(deadLetterQueue)
        .build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.SNS;
using Amazon.CDK.AWS.Lambda.EventSources;

Topic topic;

Function fn;

var deadLetterQueue = new Queue(this, "deadLetterQueue");
fn.AddEventSource(new SnsEventSource(topic, new SnsEventSourceProps {
    FilterPolicy = new Dictionary<string, object> { },
    DeadLetterQueue = deadLetterQueue
}));
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import sns "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"

var topic Topic

var fn Function

deadLetterQueue := sqs.NewQueue(this, jsii.String("deadLetterQueue"))
fn.AddEventSource(awscdk.NewSnsEventSource(topic, &SnsEventSourceProps{
	FilterPolicy: map[string]interface{}{
	},
	DeadLetterQueue: deadLetterQueue,
}))

Initializer ​

ts
new SnsEventSource(topic: ITopic, props?: SnsEventSourceProps)
python
SnsEventSource(topic: ITopic, props: typing.Optional[SnsEventSourceProps] = None)
java
new SnsEventSource(ITopic topic, SnsEventSourceProps props)
csharp
new SnsEventSource(ITopic topic, SnsEventSourceProps? props = null)
go
NewSnsEventSource(Topic ITopic, Props SnsEventSourceProps)

Properties ​

topicITopictopicITopictopicITopicTopicITopicTopicITopic#

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.