AWS Lambda SQS 集成:如何强制并发 lambda

AWS Lambda SQS integration: How to force concurrent lambdas

目前我正在使用 SQS 队列来触发 Lambda 函数。 我的 Lambda 函数一次只能处理一条 SQS 记录,我想尽快耗尽 SQS 队列

所以我设置了

Delivery Delay: to 0 seconds,

Batch size: to 1

And set Lambda to use unreserved account concurrency 1000

假设:一条SQS消息被推送到Lambda,现在正在处理中。然后另一条消息到达 SQS。我们确定会创建一个新的 lambda 来处理该消息吗?

Lambda 将串行执行但绝不会超过并发限制。

与您的情况一样,您的 SQS 队列可能一次接收 2000 条消息。 Lambda 将同时执行 运行 1000 个函数,剩下的 1000 个函数将 运行 只有在先前的执行完成后才会执行。

所以我认为快速使用队列的最佳解决方案是编写 lambda 函数一次处理多条消息并将批处理大小更改为 10。

Michael 是对的,正如 AWS 的文档所述

As the influx of messages to a queue increases, AWS Lambda automatically scales up polling activity until the number of concurrent function executions reaches 1000, the account concurrency limit, or the (optional) function concurrency limit, whichever is lower. Amazon Simple Queue Service supports an initial burst of 5 concurrent function invocations and increases concurrency by 60 concurrent invocations per minute.

因此,例如,1000 条消息一次到达队列, 第一分钟只会处理5个。

65 个 lambda 将在第二分钟同时 运行...以此类推

这是非常缓慢和明显的,特别是如果你的函数是 long-运行ning