问题描述
我正在使用AWS Lambda函数来处理Queue中的消息,它工作正常.但是,当消息可用或已添加到SQS队列中时,我需要执行此Lambda函数.
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.
是否有可能基于SQS队列触发Lambda函数.请提出一种实现此目标的方法.
Is it possible to trigger the Lambda function based on SQS queue.Please suggest one method to achieve this goal.
推荐答案
不直接支持从SQS队列调用Lambda函数.您可以在此处查看可用触发器的列表: http://docs.aws.amazon.com/lambda/latest/dg/invoking-lambda-function.html
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
可能的解决方案:
- 用Kinesis或DynamoDB替换SQS队列.两者都可以在更新时触发Lambda函数.
- 在SQS之前注入SNS.SNS可以将项目添加到SQS 和触发Lambda函数.
- Replace SQS queue with Kinesis or DynamoDB. Both can trigger Lambda functions on updates.
- 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:
- 创建CloudWatch事件规则,该规则将每N分钟(例如,每分钟)触发一次Lambda函数. 为您的SQS队列
- 创建CloudWatch警报监视
roximateNumberofMessagesVisible
参数.该警报应发布到SNS主题,这将触发Lambda函数.
- Create CloudWatch Event Rule that will trigger the Lambda function every N minutes (e.g. every minute).
- 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.
这篇关于当消息出现在SQS队列中时触发AWS中的Lambda函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!