带有 SQS 触发器的 AWS Lambda,SQS Lambda 目的地,从不添加到目的地队列 [英] AWS Lambda w/ SQS trigger, SQS Lambda Destinations, never adds to destination queue

查看:39
本文介绍了带有 SQS 触发器的 AWS Lambda,SQS Lambda 目的地,从不添加到目的地队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从 SQS 队列触发的简单 lambda 函数,我正在使用新的 Lambda 目标 功能.

I have a simple lambda function that is triggered from a SQS queue and I'm using the new Lambda Destinations functionality.

设置为从QUEUE_A触发,对payload body做一些修改,然后在成功时将其发送到QUEUE_B,或者QUEUE_ERRORS 失败.

It is set up to trigger from QUEUE_A, do some modification of the payload body, then send it to QUEUE_B on success, or QUEUE_ERRORS on failure.

QUEUE_BQUEUE_ERRORS 在 lambda 函数上设置为 目的地.

QUEUE_B and QUEUE_ERRORS are set up as Destinations on the lambda function.

当我从 CLI 触发 lambda 时,我在 QUEUE_B 上获得了一条记录良好的记录,而在 QUEUE_ERRORS 上获得了一条错误记录.所以,它似乎奏效了.

When I trigger the lambda from the CLI, I get a record on QUEUE_B with a good record, and on QUEUE_ERRORS on a bad record. So, it seems to be working.

但是,当从 SQS 触发 lambda 时,我从不QUEUE_BQUEUE_ERRORS 上获得记录.一个好的记录运行 lambda,如果记录不好,它会转到 QUEUE_A_DEADLETTER,这是我不想要的.

But, when the lambda is triggered from SQS, I never get a record on QUEUE_B or QUEUE_ERRORS. A good record runs the lambda, and on a bad record it goes to QUEUE_A_DEADLETTER, which I do not want.

我已尝试将 QUEUE_A 配置为没有重试/死信 - 如果我这样做,如果记录不好,它将永远重试(无论我设置的可见性/重试多低).

I have tried configuring QUEUE_A to have no retry/deadletter - if I do that, on a bad record it will just retry forever (no matter how low I set the visibility/retries).

接下来我可以尝试什么?

What can I try next?

编辑:
CloudWatch 准确地向我展示了我希望看到的内容 - 我在好"记录上看到了好的日志,在坏"记录上看到了堆栈跟踪/异常,所以这不是函数本身的问题 AFAIK.

EDIT:
CloudWatch shows me exactly what I expect to see - I see good logs on a "good" record, and stack traces/exceptions on "bad" records, so it is not a problem within the function itself AFAIK.

编辑:正在使用 SNS 触发器和目标替换 SQS 触发器和目标.所以,我认为这与 SQS 同步和 SNS 异步有关?有人知道吗?

EDIT: Replacing the SQS triggers and destinations with SNS triggers and destinations are working. So, I think this is related to SQS being sync and SNS being async? Does anybody know?

推荐答案

如果您同步调用 Lambda 函数,将不会触发目标.

Destinations will not be triggered if you invoke the Lambda function synchronously.

Destinations 的主要用例是了解 Lambda 函数的异步执行结果,主要是为了更好地了解请求和响应上下文、有效负载、异常堆栈跟踪等执行细节.因此,如果 Lambda 被同步调用(例如,使用 cli 或通过 SQS 触发器),不会将消息传递到目标端点.

The primary use case of Destinations is to know about the async execution results of Lambda functions, primarily to get more visibility into the execution details like request and response contexts, payloads, exception stack traces etc. So if a Lambda was invoked synchronously (say, using cli or via an SQS trigger), no messages will be delivered to the Destinations endpoints.

当您使用 CLI 时,您会使用 aws lambda invoke-async.相反,如果您使用 aws lambda invoke(同步执行 Lambda),您会看到同样的问题,您的目标端点将不会收到消息.

When you used the CLI you would have used aws lambda invoke-async. Instead if you use aws lambda invoke (which executes Lambda synchronously), you will see the same problems, your destination endpoints will not receive the message.

您可以将目的地端点保持为 SQS(您将在上面的文章中看到一个工作示例),但您的 Lambda 触发器必须更改为异步触发器.

You can keep your Destinations endpoints still as SQS (you will see a working example in the article above), but your Lambda trigger will have to change to an asynchronous one.

这篇关于带有 SQS 触发器的 AWS Lambda,SQS Lambda 目的地,从不添加到目的地队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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