Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sbstjn/lawos
SQS Worker for AWS Lambda.
https://github.com/sbstjn/lawos
amazon aws lambda sqs sqs-poller sqs-queue worker
Last synced: 5 days ago
JSON representation
SQS Worker for AWS Lambda.
- Host: GitHub
- URL: https://github.com/sbstjn/lawos
- Owner: sbstjn
- License: mit
- Created: 2017-03-05T22:41:54.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-02-12T07:00:00.000Z (almost 7 years ago)
- Last Synced: 2024-05-02T00:55:41.631Z (7 months ago)
- Topics: amazon, aws, lambda, sqs, sqs-poller, sqs-queue, worker
- Language: JavaScript
- Homepage:
- Size: 46.9 KB
- Stars: 28
- Watchers: 3
- Forks: 7
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# lawos - Lambda Worker SQS
[![npm](https://img.shields.io/npm/v/lawos.svg)](https://www.npmjs.com/package/lawos)
[![license](https://img.shields.io/github/license/sbstjn/lawos.svg)](https://github.com/sbstjn/lawos/blob/master/LICENSE.md)
[![CircleCI](https://img.shields.io/circleci/project/github/sbstjn/lawos/master.svg)](https://circleci.com/gh/sbstjn/lawos)
[![Coveralls](https://img.shields.io/coveralls/sbstjn/lawos.svg)](https://coveralls.io/github/sbstjn/lawos)Library to process messages from an Amazon SQS queue with an AWS Lambda worker function or your favorite other JavaScript environment. Works fine with [Serverless](https://github.com/sbstjn/lawos-serverless) …
## Examples
- [Serverless Amazon SQS Worker with AWS Lambda](https://sbstjn.com/serverless-sqs-worker-with-aws-lambda.html)
- [Basic usage with AWS Lambda and Serverless](https://github.com/sbstjn/lawos-serverless)## Install
```bash
$ > npm install lawos
```## Usage
### Promise for every message
```js
const AWS = require('aws-sdk');
const SQS = new AWS.SQS({apiVersion: '2012-11-05'});const Lawos = require('lawos');
const Q = new Lawos('https://sqs.eu-west-1.amazonaws.com …', SQS);Q.item(
item => new Promise(done => {
done();
})
);module.exports.handler = function(event, context, callback) {
Q.work(
() => Promise.resolve(context.getRemainingTimeInMillis() < 500)
).then(
data => {
callback(null, data);
}
);
};
```### Promise for a batch of messages
```js
const AWS = require('aws-sdk');
const SQS = new AWS.SQS({apiVersion: '2012-11-05'});const Lawos = require('lawos');
const Q = new Lawos('https://sqs.eu-west-1.amazonaws.com …', SQS);Q.list(
list => new Promise(done => {
done();
})
);module.exports.handler = function(event, context, callback) {
Q.work(
() => Promise.resolve(context.getRemainingTimeInMillis() < 500)
).then(
data => {
callback(null, data);
}
);
};
```### Use AWS Lambda instead of Promise
```js
const AWS = require('aws-sdk');
const Lawos = require('lawos');const Lambda = new AWS.Lambda({apiVersion: '2015-03-31'});
const SQS = new AWS.SQS({apiVersion: '2012-11-05'});const Q = new Lawos('https://sqs.eu-west-1.amazonaws.com …', SQS, Lambda);
Q.item('fake-function-name');
// Q.list('fake-function-name');module.exports.handler = function(event, context, callback) {
Q.work(
() => Promise.resolve(context.getRemainingTimeInMillis() < 500)
).then(
data => {
callback(null, data);
}
);
};
```## License
Feel free to use the code, it's released using the [MIT license](https://github.com/sbstjn/lawos/blob/master/LICENSE.md).
## Contributors
- [Sebastian Müller](https://sbstjn.com)