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: about 1 year 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 (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-02-12T07:00:00.000Z (over 8 years ago)
- Last Synced: 2025-04-17T04:03:40.567Z (about 1 year ago)
- Topics: amazon, aws, lambda, sqs, sqs-poller, sqs-queue, worker
- Language: JavaScript
- Homepage:
- Size: 46.9 KB
- Stars: 28
- Watchers: 2
- Forks: 7
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# lawos - Lambda Worker SQS
[](https://www.npmjs.com/package/lawos)
[](https://github.com/sbstjn/lawos/blob/master/LICENSE.md)
[](https://circleci.com/gh/sbstjn/lawos)
[](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)