简体   繁体   English

如何使用基于SQS队列的SNS触发Lambda函数

[英]How to trigger Lambda function using SNS based on SQS Queue

I am using Lambda function to push message to SQS queue. 我正在使用Lambda函数将消息推送到SQS队列。 Once the message is placed in SQS queue i need to trigger other Lambda function to process the message in Queue. 将消息放入SQS队列后,我需要触发其他Lambda函数来处理队列中的消息。

I think this we can implement using SNS. 我认为我们可以使用SNS来实现。 I am new in AWS service, Please suggest solution to trigger Lambda function based on SQS queue messages with the help of SNS. 我是AWS服务的新用户,请提出在SNS的帮助下基于SQS队列消息触发Lambda函数的解决方案。

You don't need the SNS layer in between. 您之间不需要SNS层。 From your first Lambda do 2 things 从您的第一个Lambda做2件事

  1. Place a message in SQS and 在SQS中放置一条消息,然后
  2. Trigger the Lambda that will process the event 触发将处理事件的Lambda

Out of curiosity, why do you need to put the message to SQS. 出于好奇,您为什么需要将消息发送给SQS。 If your processing is trivial then you can straightaway process the message in your first lambda function itself. 如果处理不重要,则可以在第一个lambda函数本身中直接处理消息。

This way you save the cost of SQS as well as of other Lambda 这样,您可以节省SQS以及其他Lambda的成本

I think that will depend on the urgency of processing messages. 我认为这将取决于处理消息的紧迫性。 If you want to process all the messages in Realtime then send them to SNS and subscribe your Lambda to that Topic. 如果您想实时处理所有消息,则将它们发送到SNS并将您的Lambda订阅该主题。

Another scenario can be where you are processing your messages in realtime and any failure frequently occurs due to some dependency, then in those case send it to SQS and process through a Lambda Polling later. 另一种情况是您正在实时处理消息,并且由于某种依赖性而经常发生任何故障,然后在这种情况下将其发送到SQS并在以后通过Lambda轮询进行处理。

Lambdas triggering is pretty flexible in all these cases, you can directly subscribe your lambda to SNS topic to process, Also you can schedule your lambda to run it on cron basis(useful in case of polling and processing SQS messages) 在所有这些情况下,Lambda触发都非常灵活,您可以直接将Lambda订阅SNS主题进行处理,也可以安排Lambda以cron的方式运行(在轮询和处理SQS消息时很有用)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM