# SnsDestination

Use a SNS topic as a Lambda destination.

Implements: [IDestination](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.IDestination.html)

- Source: [`aws-lambda-destinations/lib/sns.ts`](https://github.com/aws/aws-cdk/blob/v2.277.0/packages/aws-cdk-lib/aws-lambda-destinations/lib/sns.ts#L8)

## Example

TypeScript:

```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:

```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:

```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();
```

C# / .NET:

```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)
});
```

Golang:

```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

TypeScript:

```ts
new SnsDestination(topic: ITopic)
```

Python:

```python
SnsDestination(topic: ITopic)
```

Java:

```java
new SnsDestination(ITopic topic)
```

C# / .NET:

```csharp
new SnsDestination(ITopic topic)
```

Golang:

```go
NewSnsDestination(Topic ITopic)
```

## Methods

- `bind(_scope: Construct, fn: IFunction, _options?: DestinationOptions): DestinationConfig` — Returns a destination configuration.
