仅在处理相同主题的SQS订阅后才调用AWS Lambda SNS事件 [英] Invoke AWS Lambda SNS event only after SQS subscription on same topic has been processed
问题描述
我想实现一个Amazon SNS主题,该主题首先将消息传递到作为该主题的订阅者的SQS队列,然后执行也是同一主题的订阅者的AWS Lambda函数.然后,Lambda函数可以从SQS队列中读取消息并并行处理几百个消息.
I would like to implement an Amazon SNS topic which first delivers messages to a SQS queue that is a subscriber on the topic, and then executes an AWS Lambda function that is also a subscriber on the same topic. The Lambda function can then read messages from the SQS queue and process several of them in parallel (hundreds).
我的问题是,是否有任何方法可以确保发送到SNS主题的消息首先传递到SQS队列,然后才传递给Lambda函数?
My question is whether there is any way to guarantee that messages sent to the SNS topic would first be delivered to the SQS queue, and only then to the Lambda function?
这样做的目的是扩展到大量消息,而不必为每个消息单独执行Lambda函数.
The purpose of this is to scale to a large number of messages without having to execute the Lambda function separately for every single message.
推荐答案
一个SNS Topic
当前无法实现您要查找的内容.如果您将Lambda
订阅到SNS Topic
,则每次SNS Topic
收到消息时,都会并行执行特定的Lambda
.
What you're looking for is currently not possible with one SNS Topic
. If you subscribe your Lambda
to a SNS Topic
that particular Lambda
gets executed each time that SNS Topic
receives a message, in parallel.
解决方案可能是有两个SNS Topics
并将消息发布到第一个,然后让您的SQS
订阅它.成功向第一个主题提交消息后,您可以向第二个SNS Topic
发送一条消息,以执行Lambda
来处理存储在SQS
中的第一个SNS Topic
消息.
Solution might be to have two SNS Topics
and publish messages to the first one and have your SQS
subscribe to it. After successful submission of messages to this first topic you could send a message to the second SNS Topic
to execute your Lambda
to process messages the first SNS Topic
stored to SQS
.
另一种可能的解决方案可能是上述解决方案,您可以向第二个主题发送一些定期消息以运行订阅的Lambda
.这样您就可以缩放Lambda SQS Workers
.
Another possible solution might be the above, you could just send some periodic message to the second topic to run the subscribed Lambda
. This would allow you to scale your Lambda SQS Workers
.
这篇关于仅在处理相同主题的SQS订阅后才调用AWS Lambda SNS事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!