Installations
npm install serverless-offline-sns
Developer Guide
Typescript
No
Module System
ESM
Node Version
18.20.4
NPM Version
10.7.0
Releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (100%)
Developer
mj1618
Download Statistics
Total Downloads
5,425,202
Last Day
3,955
Last Week
17,494
Last Month
73,831
Last Year
885,815
GitHub Statistics
123 Stars
310 Commits
87 Forks
4 Watching
4 Branches
42 Contributors
Package Meta Information
Latest Version
0.78.1
Package Id
serverless-offline-sns@0.78.1
Unpacked Size
111.40 kB
Size
22.60 kB
File Count
17
NPM Version
10.7.0
Node Version
18.20.4
Publised On
05 Oct 2024
Total Downloads
Cumulative downloads
Total Downloads
5,425,202
Last day
-7%
3,955
Compared to previous day
Last week
-9.1%
17,494
Compared to previous week
Last month
14.5%
73,831
Compared to previous month
Last year
-20.2%
885,815
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
11
Looking for a maintainer for this project, email me if you are interested.
serverless-offline-sns
A serverless plugin to listen to offline SNS and call lambda fns with events.
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
1npm install serverless-offline-sns --save
Let serverless know about the plugin
1plugins: 2 - 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.
1custom: 2 serverless-offline-sns: 3 port: 4002 # a free port for the sns server to run on 4 debug: false 5 # host: 0.0.0.0 # Optional, defaults to 127.0.0.1 if not provided to serverless-offline 6 # sns-endpoint: http://127.0.0.1:4567 # Optional. Only if you want to use a custom SNS provider endpoint 7 # sns-subscribe-endpoint: http://127.0.0.1:3000 # Optional. Only if you want to use a custom subscribe endpoint from SNS to send messages back to 8 # accountId: 123456789012 # Optional 9 # location: .build # Optional if the location of your handler.js is not in ./ (useful for typescript)
For example, if you would like to connect to AWS and have callbacks coming via ngrok, use:
1serverless-offline-sns: 2 sns-endpoint: sns.${self:provider.region}.amazonaws.com 3 sns-subscribe-endpoint: <ngrok_url> 4 remotePort: 80 5 localPort: <ngrok_port> 6 accountId: ${self:provider.accountId}
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:
1serverless 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.
1functions: 2 pong: 3 handler: handler.pong 4 events: 5 - sns: test-topic
Or you can use the exact ARN of the topic, in 2 ways:
1functions: 2 pong: 3 handler: handler.pong 4 events: 5 - sns: 6 arn: "arn:aws:sns:us-east-1:123456789012:test-topic" # 1st way 7 - 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:
1var AWS = require("aws-sdk"); // must be npm installed to use 2var sns = new AWS.SNS({ 3 endpoint: "http://127.0.0.1:4002", 4 region: "us-east-1", 5}); 6sns.publish({ 7 Message: "{content: \"hello!\"}", 8 MessageStructure: "json", 9 TopicArn: "arn:aws:sns:us-east-1:123456789012:test-topic", 10}, () => { 11 console.log("ping"); 12});
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:
1custom: 2 serverless-offline-sns: 3 host: 0.0.0.0 # Enable plugin to listen on every local address 4 sns-subscribe-endpoint: 192.168.1.225 #Host ip address 5 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:
1custom: 2 serverless-offline-sns: 3 localPort: ${env:LOCAL_PORT} 4 remotePort: ${env:SNS_SUBSCRIBE_REMOTE_PORT} 5 host: 0.0.0.0 6 sns-subscribe-endpoint: ${env:SNS_SUBSCRIBE_ENDPOINT} 7 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.
Multiple serverless services configuration
If you have multiple serverless services, please specify a root directory:
1custom: 2 serverless-offline-sns: 3 servicesDirectory: "/path/to/directory"
The root directory must contain directories with serverless.yaml files inside.
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 -
1serverless offline-sns start
Subscribing
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
:
1// async 2const queue = await sqs.createQueue({ QueueName: 'my-queue' }).promise(); 3const subscription = await sns.subscribe({ 4 TopicArn: myTopicArn, 5 Protocol: 'sqs', 6 Endpoint: queue.QueueUrl, 7}).promise();
Contributors
Happy to accept contributions, feature requests and issues.
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 14/18 approved changesets -- score normalized to 7
Reason
SAST tool detected but not run on all commits
Details
- Info: SAST configuration detected: CodeQL
- Warn: 0 commits out of 26 are checked with a SAST tool
Reason
6 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-rhx6-c78j-4q9w
- Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j
- Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Info: jobLevel 'actions' permission set to 'read': .github/workflows/codeql-analysis.yml:28
- Info: jobLevel 'contents' permission set to 'read': .github/workflows/codeql-analysis.yml:29
- Warn: no topLevel permission defined: .github/workflows/codeql-analysis.yml:1
- Warn: no topLevel permission defined: .github/workflows/pull_requests.yml:1
- Warn: no topLevel permission defined: .github/workflows/release_tags.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:42: update your workflow using https://app.stepsecurity.io/secureworkflow/mj1618/serverless-offline-sns/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:46: update your workflow using https://app.stepsecurity.io/secureworkflow/mj1618/serverless-offline-sns/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:57: update your workflow using https://app.stepsecurity.io/secureworkflow/mj1618/serverless-offline-sns/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:71: update your workflow using https://app.stepsecurity.io/secureworkflow/mj1618/serverless-offline-sns/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/pull_requests.yml:10: update your workflow using https://app.stepsecurity.io/secureworkflow/mj1618/serverless-offline-sns/pull_requests.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/pull_requests.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/mj1618/serverless-offline-sns/pull_requests.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release_tags.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/mj1618/serverless-offline-sns/release_tags.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release_tags.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/mj1618/serverless-offline-sns/release_tags.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release_tags.yml:30: update your workflow using https://app.stepsecurity.io/secureworkflow/mj1618/serverless-offline-sns/release_tags.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release_tags.yml:32: update your workflow using https://app.stepsecurity.io/secureworkflow/mj1618/serverless-offline-sns/release_tags.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release_tags.yml:44: update your workflow using https://app.stepsecurity.io/secureworkflow/mj1618/serverless-offline-sns/release_tags.yml/main?enable=pin
- Info: 0 out of 10 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Score
4.4
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to serverless-offline-sns
@dyecode/serverless-offline-sns
Serverless plugin to run a local SNS server and call lambdas with events notifications.
serverless-offline-sns-v3
Serverless plugin to run a local SNS server and call lambdas with events notifications.
@ormu5/serverless-offline-sns
Fork of serverless-offline-sns. Serverless plugin to run a local SNS server and call lambdas with events notifications, with fixes to support SQS subscriptions.
@whisperlab/serverless-offline-sns
Serverless plugin to run a local SNS server and call lambdas with events notifications.