Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/epiphone/simple-sns-publisher
A simple SNS event publisher.
https://github.com/epiphone/simple-sns-publisher
aws-sns event-emitter event-publisher events messaging messaging-library
Last synced: 29 days ago
JSON representation
A simple SNS event publisher.
- Host: GitHub
- URL: https://github.com/epiphone/simple-sns-publisher
- Owner: epiphone
- License: mit
- Created: 2017-12-22T10:44:59.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-01-16T13:13:15.000Z (about 7 years ago)
- Last Synced: 2024-11-05T11:09:51.677Z (3 months ago)
- Topics: aws-sns, event-emitter, event-publisher, events, messaging, messaging-library
- Language: TypeScript
- Size: 37.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# simple-sns-publisher
[![Build Status](https://travis-ci.org/epiphone/simple-sns-publisher.svg?branch=master)](https://travis-ci.org/epiphone/simple-sns-publisher) [![codecov](https://codecov.io/gh/epiphone/simple-sns-publisher/branch/master/graph/badge.svg)](https://codecov.io/gh/epiphone/simple-sns-publisher)
A simple wrapper over [AWS NodeJS SDK](https://aws.amazon.com/sdk-for-node-js/) for publishing JSON-formatted messages on a SNS topic.
## ~~Install~~
~~`yarn install simple-sns-publisher`~~
**Still under development!**
## Usage
```typescript
import { SimpleSNSPublisher } from 'simple-sns-publisher'const sns = new SimpleSNSPublisher()
sns.publish({
message: { eventId: '1234-asdf', someKey: 'value' },
topicARN: 'arn:aws:sns:us-west-2:111122223333:MyTopic'
})
```The above results in the following SNS message:
```json
{
"Message": {"eventId": "1234-asdf", "someKey": "value"},
"TopicArn": "arn:aws:sns:us-west-2:111122223333:MyTopic"
}
```## Configuration options
```typescript
/**
* SNS publisher constructor options.
*/
export interface ISimpleSNSPublisherOptions {
/**
* AWS client configuration passed on to the SNS object constructor.
* Define your API keys either here or in environment variables.
*/
awsConfig: AWS.SNS.Types.ClientConfiguration/**
* Whether logging is enabled or not - defaults to true.
*/
logEnabled: boolean/**
* The handler used to log publish result/error - defaults to
* console.log/console.error. E.g. a Winston instance can be passed here.
*/
logHandler: {
info: (args: { options: IPublishOptions; result: AWS.SNS.Types.PublishResponse }) => any
error: (args: { options: IPublishOptions; error: AWS.AWSError }) => any
}/**
* Logging level - defaults to 'info'. Set to 'error' to only log errors.
*/
logLevel: 'info' | 'error'/**
* Whether publish errors should be propagated or just logged - defaults to true.
*/
throwError: boolean
}
```## Related projects
- The handy [aws-sdk-mock](https://github.com/dwyl/aws-sdk-mock) mocking library used for tests
## TODO
- Set SNS message attributes to allow filtering