Skip to content

iopipe/sqs-to-lambda-async

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SQS to Lambda (Async)

CircleCI styled with prettier

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.

Requirements

  • Node >= 4.3.2
  • NPM >= 2.14.12

Install

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'
  }
]);

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:

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

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

postInvoke (function: optional)

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
    }
  }
]);

Contributing

  • This project uses Prettier. Please execute npm run eslintFix to auto-format the code before submitting pull requests.