https://github.com/iopipe/sqs-to-lambda-async
Process SQS messages with Lambda, asynchronously
https://github.com/iopipe/sqs-to-lambda-async
async aws-lambda lambda serverless sqs
Last synced: 5 months ago
JSON representation
Process SQS messages with Lambda, asynchronously
- Host: GitHub
- URL: https://github.com/iopipe/sqs-to-lambda-async
- Owner: iopipe
- License: apache-2.0
- Created: 2017-06-28T19:34:05.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-09-19T13:24:23.000Z (over 6 years ago)
- Last Synced: 2024-12-06T11:36:26.254Z (6 months ago)
- Topics: async, aws-lambda, lambda, serverless, sqs
- Language: JavaScript
- Size: 48.8 KB
- Stars: 27
- Watchers: 4
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# SQS to Lambda (Async)
[](https://circleci.com/gh/iopipe/sqs-to-lambda-async)
[](https://github.com/prettier/prettier)So you want to trigger a Lambda function via SQS? Great! You might be able to use [sqs-to-lambda](https://github.com/robinjmurphy/sqs-to-lambda). But what if you want your Lambda function to delete the SQS message, instead of the sqs-to-lambda implementation? Or, what if you want to setup multiple SQS => Lambda configurations? That's where this package comes in.
## Requirements
- Node >= `4.3.2`
- NPM >= `2.14.12`## Install
With [yarn](https://yarnpkg.com) (recommended) in project directory:
```
yarn add sqs-to-lambda-async
```With npm in project directory:
```
npm install sqs-to-lambda-async
```Then, run your application:
```js
import worker from 'sqs-to-lambda-async';worker([
{
queueUrl: 'sqs-queue-url-here',
functionName: 'lambda-arn-here'
}
]);
```## Config
The package accepts an array of mapping configurations. A mapping configuration is an object with the following properties:
#### `queueUrl` (string: required)
The SQS queue you want to pull from.
#### `functionName` (string: required)
The Lambda function you want to execute.
#### `messageFormatter` (function: optional)
A function that allows transformation of the SQS message before send to Lambda.
Example:
```js
worker([
{
queueUrl: 'sqs-queue-url-here',
functionName: 'lambda-arn-here',
messageFormatter: (msg) => {
return Object.assign({}, msg, {
Body: 'reconfigure the sqs body here'
})
}
}
]);
```#### `deleteMessage` (boolean: optional, default = false)
Use this flag to allow this package to delete the message for you, instead of your Lambda function.
#### `maxNumberOfMessages` (integer: optional, default = 5)
The maximum number of messages to return. [AWS Documenation](http://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_ReceiveMessage.html)
#### `waitTimeSeconds` (integer: optional, default = 5)
The duration (in seconds) for which the call waits for a message to arrive in the queue before returning. [AWS Documenation](http://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_ReceiveMessage.html)
#### `postInvoke` (function: optional)
Optional callback that is invoked after each lambda invocation. Useful for error handling.
Example:
```js
worker([
{
queueUrl: 'sqs-queue-url-here',
functionName: 'lambda-arn-here',
postInvoke(err, value){
// err will be undefined if lambda invoked successfully
// value includes FunctionName and Payload
}
}
]);
```## Contributing
- This project uses [Prettier](https://github.com/prettier/prettier). Please execute `npm run eslintFix` to auto-format the code before submitting pull requests.