GithubHelp home page GithubHelp logo

bennettrogers / serverless-offline-sns Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mj1618/serverless-offline-sns

0.0 2.0 0.0 153 KB

A serverless plugin to run an SNS server and call lambdas with events notifications.

License: MIT License

TypeScript 100.00%

serverless-offline-sns's Introduction

serverless-offline-sns

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

Docs

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

Prerequisites

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.

Installation

Install the plugin

npm install serverless-offline-sns --save

Let serverless know about the plugin

plugins:
  - serverless-offline-sns

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

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

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

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.

functions:
  pong:
    handler: handler.pong
    events:
      - sns: test-topic

Or you can use the exact ARN of the topic:

functions:
  pong:
    handler: handler.pong
    events:
      - sns:
         arn: "arn:aws:sns:us-east-1:123456789012:test-topic"

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: "http://127.0.0.1:4002",
  region: "us-east-1",
});
sns.publish({
  Message: "hello!",
  MessageStructure: "json",
  TopicArn: "arn:aws:sns:us-east-1:123456789012:test-topic",
}, () => {
  console.log("ping");
});

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

Usage

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

Contributors

Happy to accept contributions, feature requests and issues.

Thanks goes to these wonderful people (emoji key):


Matthew James

๐Ÿ’ฌ ๐Ÿ’ป ๐ŸŽจ ๐Ÿ“– ๐Ÿ’ก

darbio

๐Ÿ› ๐Ÿ’ป

TiVoMaker

๐Ÿ› ๐Ÿ’ป ๐ŸŽจ ๐Ÿ“–

Jade Hwang

๐Ÿ›

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

serverless-offline-sns's People

Contributors

bennettrogers avatar darbio avatar mj1618 avatar tivomaker avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.