Skip to content
v2.275.0

SnsDestination Class ​

Use a SNS topic as a Lambda destination.

Example ​

ts
// An sns topic for successful invocations of a lambda function
import * as sns from 'aws-cdk-lib/aws-sns';

const myTopic = new sns.Topic(this, 'Topic');

const myFn = new lambda.Function(this, 'Fn', {
  runtime: lambda.Runtime.NODEJS_LATEST,
  handler: 'index.handler',
  code: lambda.Code.fromAsset(path.join(__dirname, 'lambda-handler')),
  // sns topic for successful invocations
  onSuccess: new destinations.SnsDestination(myTopic),
})
python
# An sns topic for successful invocations of a lambda function
import aws_cdk.aws_sns as sns


my_topic = sns.Topic(self, "Topic")

my_fn = lambda_.Function(self, "Fn",
    runtime=lambda_.Runtime.NODEJS_LATEST,
    handler="index.handler",
    code=lambda_.Code.from_asset(path.join(__dirname, "lambda-handler")),
    # sns topic for successful invocations
    on_success=destinations.SnsDestination(my_topic)
)
java
// An sns topic for successful invocations of a lambda function
import software.amazon.awscdk.services.sns.*;


Topic myTopic = new Topic(this, "Topic");

Function myFn = Function.Builder.create(this, "Fn")
        .runtime(Runtime.NODEJS_LATEST)
        .handler("index.handler")
        .code(Code.fromAsset(join(__dirname, "lambda-handler")))
        // sns topic for successful invocations
        .onSuccess(new SnsDestination(myTopic))
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
// An sns topic for successful invocations of a lambda function
using Amazon.CDK.AWS.SNS;


var myTopic = new Topic(this, "Topic");

var myFn = new Function(this, "Fn", new FunctionProps {
    Runtime = Runtime.NODEJS_LATEST,
    Handler = "index.handler",
    Code = Code.FromAsset(Join(__dirname, "lambda-handler")),
    // sns topic for successful invocations
    OnSuccess = new SnsDestination(myTopic)
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// An sns topic for successful invocations of a lambda function
import sns "github.com/aws/aws-cdk-go/awscdk"


myTopic := sns.NewTopic(this, jsii.String("Topic"))

myFn := lambda.NewFunction(this, jsii.String("Fn"), &FunctionProps{
	Runtime: lambda.Runtime_NODEJS_LATEST(),
	Handler: jsii.String("index.handler"),
	Code: lambda.Code_FromAsset(path.join(__dirname, jsii.String("lambda-handler"))),
	// sns topic for successful invocations
	OnSuccess: destinations.NewSnsDestination(myTopic),
})

Initializer ​

ts
new SnsDestination(topic: ITopic)
python
SnsDestination(topic: ITopic)
java
new SnsDestination(ITopic topic)
csharp
new SnsDestination(ITopic topic)
go
NewSnsDestination(Topic ITopic)

Methods ​

bind(_scope: Construct, fn: IFunction, _options?: DestinationOptions): DestinationConfigdef bind(self, _scope: Construct, fn: IFunction, _options: typing.Optional[DestinationOptions] = None) -> DestinationConfigpublic DestinationConfig bind(Construct _scope, IFunction fn, DestinationOptions _options)public DestinationConfig Bind(Construct _scope, IFunction fn, DestinationOptions? _options = null)func Bind(_scope Construct, Fn IFunction, _options DestinationOptions) DestinationConfig#
Returns a destination configuration.