SQS 用多条记录/消息触发 Lambda? [英] SQS triggers Lambda with multiple records/messages?

查看:44
本文介绍了SQS 用多条记录/消息触发 Lambda?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我观察到一个异常(好吧,在我的 POV 中)功能,当我设置 SQS 以触发 Lambda 时,当新消息到达时,Lambda 会在其事件正文中触发超过 1 条记录/消息.

完整的设置是 S3 (PutObjectEvent) -> SNS 主题 -> SQS -> Lambda.

异常行为是,例如,假设我将 15 个对象放入 S3,然后每个对象将事件转发到 SNS,然后我可以观察到,SQS 填充了 15 条消息.但是,当 Lambda 开始触发时,在这 15 条消息中,只有 11 条 Lambda 触发,其中一些在其事件正文中包含超过 1 条记录/消息.

我已经搜索了 AWS 文档,但没有找到具体的答案.请注意,这些 Lambda 不会轮询 SQS 或失败或继续重试.它们执行得非常好,只是被检查的事件主体在其中显示了 1 个以上的记录.

解决方案

查看 SQS Lambda 消息的示例事件数据 此处.消息是一组记录,直接暗示消息中可能有多个SQS记录.

有关 SQS Lambda 集成的文档 也很清楚声明 Batch Size 设置控制 Lambda 函数在一次调用中可以从 SQS 接收多少条记录,默认值为 10.如果您只希望您的 Lambda 函数一次接收一条消息,您需要将 Batch Size 设置修改为 1.

I've observed an abnormal (well, in my POV) feature, where when I setup SQS to trigger a Lambda, when new messages arrive, lambdas get triggered with more than 1 record/message inside its event body.

Full setup is S3 (PutObjectEvent) -> SNS topic -> SQS -> Lambda.

The abnormal behaviour is that for example, let's say I put 15 objects inside S3, which then forwards an event to SNS per each object, which then I can observe, SQS gets populated with 15 messages. However, when Lambdas start triggering, out of those 15 messages, only 11 Lambdas trigger, some of them containing more than 1 record/message inside its event body.

I've scoured the AWS documentation, but haven't found a concrete answer. Please note, these Lambdas do NOT poll SQS or fail or keep retrying. They execute perfectly fine, its just that inspected event body shows more than 1 record inside of it.

解决方案

Look at the sample event data for an SQS Lambda message here. The message is an array of records, which directly implies that there may be more than one SQS record in the message.

The documentation on SQS Lambda integration also clearly states that the Batch Size setting controls how many records a Lambda function may receive from SQS in a single call, with the default being 10. If you only want your Lambda functions to receive one message at a time you need to modify the Batch Size setting to be 1.

这篇关于SQS 用多条记录/消息触发 Lambda?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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