---
title: Amazon SNS
---
# Amazon SNS

Svix can deliver webhooks directly to an Amazon SNS topic, without your customers having to set up any listener endpoint or write any glue code.

When **Advanced Endpoint Types** is [enabled](/advanced-endpoints#enabling-advanced-endpoint-types), your customers will see the option to use an SNS destination in the [App Portal](/app-portal).

![SNS Endpoint Create](/img/advanced-endpoints/sns-create.png)

They will be able to configure the connection right in the App Portal:

- `topicArn` — the ARN of the SNS topic to publish to.
- `region`, `accessKeyId`, `secretAccessKey` — the AWS region and credentials used to authenticate.

Every webhook in the batch is published to the topic as a separate message.

# Transformations

By default, all SNS Endpoints come bundled with the following transformation code.

```JavaScript
/**
 * @param input - The input object
 * @param input.events - The array of webhooks in the batch. The number of webhooks in the batch is capped by the endpoint's batch size.
 * @param input.events[].payload - The message payload (string or JSON).
 * @param input.events[].eventType - The message event type (string).
 *
 * @returns Object containing the response.
 * @returns returns.messages - The array of SNS messages to send to the SNS topic.
 * @returns returns.messages[].payload - The content of the message (string).
 * @returns returns.messages[].subject - An optional subject of the message (string).
 */
function handler(input) {
  const messages = input.events.map((event) => ({
    payload: event,
  }));

  return {
    messages,
  };
}
```

`input.events` is the list of webhooks received by the endpoint, processed in batches.

Each entry in the returned `messages` array is published as a separate SNS message. The `payload` becomes the message body, and the optional `subject` becomes the SNS subject. By default, each webhook is published as its serialized JSON, with no subject.

For example, if the endpoint receives the following messages:

```json
{
  "eventType": "user.created",
  "payload": "{\"email\": \"joe@enterprise.io\"}"
}
```

```json
{
  "eventType": "user.login",
  "payload": "{\"id\": 12, \"timestamp\": \"2025-07-21T14:23:17.861Z\"}"
}
```

The default transformation code would publish two messages to your topic, with the following bodies.

```json
{"payload":{"email":"joe@enterprise.io"},"eventType":"user.created"}
```

```json
{"payload":{"id":12,"timestamp":"2025-07-21T14:23:17.861Z"},"eventType":"user.login"}
```

To control the message bodies, or to set a subject, return your own array of `messages`. Each message's `payload` becomes the body of one SNS message, and `subject` is published as that message's SNS subject.

```JavaScript
function handler(input) {
  const messages = input.events.map((event) => ({
    payload: JSON.stringify(event.payload),
    subject: event.eventType
  }));

  return {
    messages,
  };
}
```

SNS accepts at most 10 messages per batch request, so larger batches are automatically split across multiple `PublishBatch` calls.
