简体   繁体   English

同步调用lambda时,如何向DLQ添加失败信息?

[英]How to add failure messages to DLQ when lambda is invoked synchronously?

I have structure similar to this我有类似的结构

SQS -> Lambda -> DLQ SQS -> Lambda -> DLQ

When Lambda is invoked asynchronously like below then failure messages are getting added successfully to DLQ.当像下面这样异步调用 Lambda 时,失败消息将成功添加到 DLQ。

$ aws lambda invoke --function-name my-function --invocation-type Event --payload '{ "key": "value" }' response.json

But when lambda gets triggered on adding new messages to SQS then on failure, messages doesn't store in DLQ.但是当 lambda 在向 SQS 添加新消息时被触发然后失败时,消息不会存储在 DLQ 中。

I found that events triggered when new message published to SQS are synchronous in nature.我发现当新消息发布到 SQS 时触发的事件本质上是同步的。

Lambda polls the queue and invokes your function synchronously with an event that contains queue messages. Lambda 轮询队列并使用包含队列消息的事件同步调用您的函数。

Reference - https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html .参考 - https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html

So I want either-所以我要么——

  1. SQS event trigger invoke lambda asynchronously SQS 事件触发器异步调用 lambda

or要么

  1. Messages gets stored in DLQ on synchronous invocation of Lambda as well.消息也会在同步调用 Lambda 时存储在 DLQ 中。
  1. DLQ is used not to store error messages but to store failed events, that can be handled again later. DLQ 不用于存储错误消息,而是用于存储失败的事件,这些事件可以在以后再次处理。
  2. CloudWatch is used to store and show logs (including errors) for Lambda and any other AWS service. CloudWatch 用于存储和显示 Lambda 和任何其他 AWS 服务的日志(包括错误)。
  3. The idea behind SQS triggering Lambda is that in case of Lambda failure, the event will be handled again by Lambda later. SQS 触发 Lambda 背后的想法是,如果 Lambda 失败,事件将在稍后由 Lambda 再次处理。
    It's the same idea as DLQ but implemented differently.它与 DLQ 的想法相同,但实现方式不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM