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

落爺英雄遲暮 提交于 2021-02-18 06:59:13

问题


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.


回答1:


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:


Lambda now supports SQS as a native event source

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



来源:https://stackoverflow.com/questions/41137487/trigger-lambda-function-in-aws-when-the-message-is-present-in-sqs-queue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!