SNS 到 Lambda 与 SNS 到 SQS 到 Lambda [英] SNS to Lambda vs SNS to SQS to Lambda

查看:41
本文介绍了SNS 到 Lambda 与 SNS 到 SQS 到 Lambda的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有人可以帮助解释,我正在尝试了解我的工作流程中是否需要 SQS.在我的应用程序中,当执行操作时,它会将信息提交给调用 Lambda 进行一些处理的 SNS 主题.这很好用.

I'm trying to understand whether I need SQS in my workflow if someone can help explain. In my app, when an action is taken, it submits info to SNS topic which invokes Lambda to do some processing. This is working great as it is.

当我在网上做研究时,似乎人们也在这个堆栈中使用 SQS,SNS 将信息放在 SQS 上,然后 SQS 会调用 Lambda.

When I do research online, it seems that people are using SQS in this stack as well where SNS would put info on SQS and then SQS would then invoke Lambda.

我想我想了解的是在这方面对 SQS 的需求.这增加了什么价值?换句话说,直接从 SNS 调用我的 Lambda 会失去什么?

I guess what I'm trying to understand is the need for SQS in this. What value does that add? In other words, what am I losing by invoking my Lambda directly from SNS?

推荐答案

在 SNS 和 Lambda 之间使用 SQS 的主要优势是重新处理.假设 Lambda 由于某种原因(例如超时或内存不足)无法处理某些事件,您可以增加超时(最多 5 分钟)或内存(最多 1.5GB)并重新开始轮询,您可以重新处理较旧的事件.

Primary advantage of having a SQS in between SNS and Lambda is Reprocessing. Assume that the Lambda fails to process certain event for some reason (e.g. timeout or lack of memory footprint), you can increase the timeout (to max 5 minutes) or memory (to max of 1.5GB) and restart your polling and you can reprocess the older events.

这在 SNS 到 Lambda 的情况下是不可能的,其中如果 Lambda 失败,事件就会丢失.并且即使您配置了 DLQ,您仍然必须为单独读取和处理消息做好准备

This would not be possible in case of SNS to Lambda, wherein if Lambda fails the event is lost. And even if you configure DLQ you would still have to make provisions for reading that separately and processing the message

因此,如果您的活动很重要并且您不想错过它们,那么请选择 SNS - SQS - Lambda

So if your events are critical and you don't want to miss out on them, then go for SNS - SQS - Lambda

使用 SQS 的另一个优势是节省 Lambda 调用的成本(感谢 @codesinthedark 提出这一点).您可以获得更好的扩展性和更低的成本,因为它允许您批量处理消息.因此,可以为一批 10 条消息执行一个 lambda,而在直接 SNS 的情况下,每条消息都会触发 lambda 调用.

The other advantage of having SQS is cost saving on Lambda invocations (Thanks @codesinthedark for bringing this up). You can have much better scaling and less cost, as it allows you to process messages in batches. So one lambda can be executed for a batch of 10 messages while in case of direct SNS each message would trigger a lambda invocation.

这篇关于SNS 到 Lambda 与 SNS 到 SQS 到 Lambda的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆