6
votes

I am using AWS Lambda function to process the messages in Queue it's working fine. But i need to execute this Lambda function when messages available or added in SQS queue.

Is it possible to trigger the Lambda function based on SQS queue.Please suggest one method to achieve this goal.

2

2 Answers

16
votes

Invoking Lambda functions from SQS queues is not directly supported. You can see the list of available triggers here: http://docs.aws.amazon.com/lambda/latest/dg/invoking-lambda-function.html

Possible solutions:

  1. Replace SQS queue with Kinesis or DynamoDB. Both can trigger Lambda functions on updates.
  2. Inject SNS before SQS. SNS can add items to SQS and trigger Lambda function.

If you don't need near real-time processing, these two options are also valid:

  1. Create CloudWatch Event Rule that will trigger the Lambda function every N minutes (e.g. every minute).
  2. Create CloudWatch alarm watching ApproximateNumberOfMessagesVisible parameter for your SQS queue. This alarm should publish to an SNS topic, which in turn will trigger Lambda function.
2
votes