Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger Lambda Function in AWS when the message is present in SQS Queue

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.

like image 991
Team Avatar asked Dec 14 '16 07:12

Team


2 Answers

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.
like image 122
Sergey Kovalev Avatar answered Nov 15 '22 11:11

Sergey Kovalev


Lambda now supports SQS as a native event source

https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html

like image 33
andrhamm Avatar answered Nov 15 '22 11:11

andrhamm