So you want to trigger a Lambda function via SQS? Great! You might be able to use 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.
- Node >=
4.3.2
- NPM >=
2.14.12
With yarn (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:
import worker from 'sqs-to-lambda-async';
worker([
{
queueUrl: 'sqs-queue-url-here',
functionName: 'lambda-arn-here'
}
]);
The package accepts an array of mapping configurations. A mapping configuration is an object with the following properties:
The SQS queue you want to pull from.
The Lambda function you want to execute.
A function that allows transformation of the SQS message before send to Lambda.
Example:
worker([
{
queueUrl: 'sqs-queue-url-here',
functionName: 'lambda-arn-here',
messageFormatter: (msg) => {
return Object.assign({}, msg, {
Body: 'reconfigure the sqs body here'
})
}
}
]);
Use this flag to allow this package to delete the message for you, instead of your Lambda function.
The maximum number of messages to return. AWS Documenation
The duration (in seconds) for which the call waits for a message to arrive in the queue before returning. AWS Documenation
Optional callback that is invoked after each lambda invocation. Useful for error handling.
Example:
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
}
}
]);
- This project uses Prettier. Please execute
npm run eslintFix
to auto-format the code before submitting pull requests.