从一个 SQS 触发器触发多个 lambda 函数 [英] Triggering multiple lambda functions from one SQS trigger

查看:33
本文介绍了从一个 SQS 触发器触发多个 lambda 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定我是否理解 AWS Lambda - SQS 正确触发.我是否可以将其配置为一个 SQS 队列可以根据消息正文或消息属性触发不同的 lambda 函数?

I'm not sure if I understand AWS Lambda - SQS triggers correctly. Can I possibly configure it in such a way that one SQS queue can trigger different lambda functions depending on the message body or a message attribute?

我的用例:我有三个不同的 lambda 函数(processCricket、processFootball、processTennis),每个函数执行一个独特的功能.我有一个接收消息的队列(processGame).队列中的每条消息都有一个属性type",它可以是Cricket"、Football"或Tennis".我可以根据消息上的类型"调用不同的 lambda 函数吗?

My use case: I have three different lambda functions (processCricket, processFootball, processTennis) each of which perform a unique function. I have a single queue (processGame) which receives messages. Each message on the queue has a attribute "type" which is either "Cricket", "Football" or "Tennis". Can I invoke a different lambda function depending on the "type" on the message?

选项 1: 配置 SQS 以根据类型触发不同的 lambda 函数(不确定我是否可以这样做)

Option 1: Configure SQS to trigger a different lambda function depending on the type (Not sure if I can do this)

选项 2: 配置一个可以检查类型的 lambda 函数,然后根据其类型调用其他 lambda 函数

Option 2: Configure one lambda function which can check type and then call the other lambda functions depending on its type

选项 3: 为每个 lambda 创建单独的队列.通过将消息添加到适当的队列来控制哪个 lambda 处理消息.

Option 3: Create separate queues for each lambda. Control which lambda processes the message by adding the message to the appropriate queue.

推荐答案

选项 1:根据类型配置 SQS 以触发不同的 lambda 函数

Option 1: Configure SQS to trigger a different lambda function depending on the type

在被 lambda 使用之前,您无法知道 type.所以这是不可能的.

You can't know about the type until it is consumed by the lambda. So this one is not possible.

选项 2:配置一个可以检查类型的 lambda 函数,然后根据其类型调用其他 lambda 函数

Option 2: Configure one lambda function which can check type and then call the other lambda functions depending on its type

是的,这是第一个选项的可能"方式.但根据您的使用情况,它可能会花费更多".当您以批处理模式使用 sqs 时,您必须通过多次检查来调用多个 lambda.

Yes it is the "possible" way of first option. but it may cost "more" depending on your usage. When you consume the sqs in batch mode, then you have to invoke multiple lambdas by making multiple checks.

选项 3:为每个 lambda 创建单独的队列.通过将消息添加到适当的队列来控制哪个 lambda 处理消息.

Option 3: Create separate queues for each lambda. Control which lambda processes the message by adding the message to the appropriate queue.

在我看来,这可能是最好的选择.您可以为每个队列配置不同的 DLQ,根据您的业务规则设置不同的批次大小,无需额外的 lambda 来增加复杂性".

In my opinion, this could be the best option. You can configure different DLQ for each queue, set different batch size depending on your business rules, no need for extra lambda to increase "complexity".

这篇关于从一个 SQS 触发器触发多个 lambda 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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