Lambda批次拆分为部分成功

Lambda批次拆分为部分成功

本文介绍了将SQS Lambda批次拆分为部分成功/部分失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AWS SQS-> Lambda集成允许您批量处理传入消息,在此配置您可以在单个批处理中接收的最大数量.如果在处理过程中引发异常以指示失败,则在可见性超时过后,所有消息都不会从传入队列中删除,而是可以由另一个lambda进行处理.

The AWS SQS -> Lambda integration allows you to process incoming messages in a batch, where you configure the maximum number you can receive in a single batch. If you throw an exception during processing, to indicate failure, all the messages are not deleted from the incoming queue and can be picked up by another lambda for processing once the visibility timeout has passed.

出于性能原因,是否有任何方法可以保留批处理,但允许批处理中的某些消息成功(并从入站队列中删除),而只保留某些批处理未删除?

Is there any way to keep the batch processing, for performance reasons, but allow some messages from the batch to succeed (and be deleted from the inbound queue) and only leave some of the batch un-deleted?

推荐答案

一种选择是手动将失败的消息发送回队列,然后以成功的方式答复SQS,以确保没有重复项.

One option is to manually send back the failed messages to the queue, and then replying with a success to the SQS so that there are no duplicates.

您可以执行类似设置失败计数的操作,这样,如果所有消息失败,则可以简单地为所有消息返回失败状态,否则,如果失败计数为<10(10是您可以从SQS-> Lambda事件获得的最大批处理大小),然后您可以将失败的消息分别发送回队列,然后以成功消息进行答复.

You could do something like setting up a fail count, so that if all messages failed you can simply return a failed status for all messages, otherwise if the fail count is < 10 (10 being the max batch size you can get from SQS -> Lambda event) then you can individually send back the failed messages to the queue, and then reply with a success message.

此外,为避免任何可能的无限重试循环,请在将事件发送回队列之前,向事件添加一个属性,例如重试"计数,并在重试"大于X时删除该事件.

Additionally, to avoid any possible infinite retry loop, add a property to the event such as a "retry" count before sending it back to the queue, and drop the event when "retry" is greater than X.

这篇关于将SQS Lambda批次拆分为部分成功/部分失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 05:23