Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including serverless-offline-sns with all npm packages installed. Try it out:

var serverlessOfflineSns = require("serverless-offline-sns")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

serverless-offline-sns v0.65.0

Serverless plugin to run a local SNS server and call lambdas with events notifications.


A serverless plugin to listen to offline SNS and call lambda fns with events.

serverless Build Status npm version PRs Welcome License: MIT All Contributors


For an example of a working application please see serverless-offline-sns-example


This plugin provides an SNS server configured automatically without you specifying an endpoint.

If you'd rather use your own endpoint, e.g. from your AWS account or a localstack SNS server endpoint, you can put it in the custom config. See below for details.


Install the plugin

npm install serverless-offline-sns --save

Let serverless know about the plugin

  - serverless-offline-sns

Note that ordering matters when used with serverless-offline and serverless-webpack. serverless-webpack must be specified at the start of the list of plugins.

Configure the plugin with your offline SNS endpoint, host to listen on, and a free port the plugin can use.

    port: 4002 # a free port for the sns server to run on
    debug: false
    # host: # Optional, defaults to if not provided to serverless-offline
    # sns-endpoint: # Optional. Only if you want to use a custom endpoint
    # accountId: 123456789012 # Optional

In normal operation, the plugin will use the same --host option as provided to serverless-offline. The host parameter as shown above overrides this setting.

If you are using the serverless-offline plugin serverless-offline-sns will start automatically. If you are not using this plugin you can run the following command instead:

serverless offline-sns start


Configure your function handlers with events as described in the Serverless SNS Documentation

Here's an example serverless.yml config which calls a function on an SNS notifcation. Note that the offline-sns plugin will automatically pick up this config, subscribe to the topic and call the handler on an SNS notification.

    handler: handler.pong
      - sns: test-topic

Or you can use the exact ARN of the topic, in 2 ways:

    handler: handler.pong
      - sns:
         arn: "arn:aws:sns:us-east-1:123456789012:test-topic" # 1st way
      - sns: "arn:aws:sns:us-east-1:123456789012:test-topic-two" # 2nd way

Here's a demo of some code that will trigger this handler:

var AWS = require("aws-sdk"); // must be npm installed to use
var sns = new AWS.SNS({
  endpoint: "",
  region: "us-east-1",
  Message: "hello!",
  MessageStructure: "json",
  TopicArn: "arn:aws:sns:us-east-1:123456789012:test-topic",
}, () => {

Note the region that offline-sns will listen on is what is configured in your serverless.yml provider.

Localstack docker configuration

In order to listen to localstack SNS event, if localstack is started with docker, you need the following:

    host: # Enable plugin to listen on every local address
    sns-subscribe-endpoint: #Host ip address
    sns-endpoint: http://localhost:4575 # Default localstack sns endpoint

What happens is that the container running localstack will execute a POST request to the plugin, but to reach outside the container, it needs to use the host ip address.

Hosted AWS SNS configuration

In order to listen to a hosted SNS on AWS, you need the following:

    localPort: ${env:LOCAL_PORT}
    remotePort: ${env:SNS_SUBSCRIBE_REMOTE_PORT}
    sns-subscribe-endpoint: ${env:SNS_SUBSCRIBE_ENDPOINT}
    sns-endpoint: ${env:SNS_ENDPOINT}```

If you want to unsubscribe when you stop your server, then call sls offline-sns cleanup when the script exits.


If you use serverless-offline this plugin will start automatically.

However if you don't use serverless-offline you can start this plugin manually with -

serverless offline-sns start


serverless-offline-sns supports http, https, and sqs subscriptions. email, email-json, sms, application, and lambda protocols are not supported at this time.

When using sqs the Endpoint for the subscription must be the full QueueUrl returned from the SQS service when creating the queue or listing with ListQueues:

// async
const queue = await sqs.createQueue({ QueueName: 'my-queue' }).promise();
const subscription = await sns.subscribe({
    TopicArn: myTopicArn,
    Protocol: 'sqs',
    Endpoint: queue.QueueUrl,


Happy to accept contributions, feature requests and issues.

Thanks goes to these wonderful people (emoji key):

| [
Matthew James](
[💬](#question-mj1618 "Answering Questions") [💻]( "Code") [🎨](#design-mj1618 "Design") [📖]( "Documentation") [💡](#example-mj1618 "Examples") | [
[🐛]( "Bug reports") [💻]( "Code") | [
[🐛]( "Bug reports") [💻]( "Code") [🎨](#design-TiVoMaker "Design") [📖]( "Documentation") | [
Jade Hwang](
[🐛]( "Bug reports") | [
Bennett Rogers](
[🐛]( "Bug reports") [💻]( "Code") | [
Julius Breckel](
[💻]( "Code") [💡](#example-jbreckel "Examples") [⚠️]( "Tests") | [
[🐛]( "Bug reports") [💻]( "Code") | | :---: | :---: | :---: | :---: | :---: | :---: | :---: | | [
Jamie Learmonth](
[🐛]( "Bug reports") | [
Gevorg A. Galstyan](
[🐛]( "Bug reports") [💻]( "Code") | [
Ivan Montiel](
[🐛]( "Bug reports") [💻]( "Code") [⚠️]( "Tests") | [
Matt Ledom](
[💻]( "Code") [🎨](#design-mledom "Design") | [
Keith Kirk](
[💻]( "Code") [🎨](#design-kmfk "Design") | [
Kobi Meirson](
[💻]( "Code") | [
Steve Green](
[💻]( "Code") | | [
[🐛]( "Bug reports") [💻]( "Code") [🎨](#design-DanielSchaffer "Design") | [
Zdenek Farana](
[💻]( "Code") | [
Daniel Maricic](
[💻]( "Code") | [
Brandon Evans](
[💻]( "Code") | [
AJ Stuyvenberg](
[💬](#question-astuyve "Answering Questions") [💻]( "Code") [⚠️]( "Tests") | [
[⚠️]( "Tests") [💻]( "Code") | [
[🐛]( "Bug reports") [💻]( "Code") | | [
PJ Cavanaugh](
[🐛]( "Bug reports") [💻]( "Code") | [
Victor Ferreira](
[🐛]( "Bug reports") [💻]( "Code") | [
[📖]( "Documentation") | [
Matt Telesky](
[🐛]( "Bug reports") [💻]( "Code") | [
Garrett Scott](
[🐛]( "Bug reports") [💻]( "Code") | [
Patrice Gargiolo](
[📖]( "Documentation") | [
Michael W. Martin](
[🐛]( "Bug reports") [💻]( "Code") | | [
[🐛]( "Bug reports") [💻]( "Code") | [
Matthew Miller](
[🐛]( "Bug reports") [💻]( "Code") |

This project follows the all-contributors specification. Contributions of any kind welcome!

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free