简体   繁体   English

AWS 事件桥 Lambda 调用

[英]AWS Event Bridge Lambda invocation

I have configured a lambda function as EventBridge rule target and I have configured a Dead Letter Queue on the EventBridge rule to capture exceptions.我已将 lambda function 配置为 EventBridge 规则目标,并且已在 EventBridge 规则上配置死信队列以捕获异常。 Now, if the lambda function fails, Event Bridge does not recognize that failure as an error.现在,如果 lambda function 失败,Event Bridge 不会将该失败识别为错误。 Since the EventBridge invocation to the Lambda is asynchronous, for EventBridge it is enough to reach the lambda to consider the event as successfull,but in this way I am not able to track and retry events once lambda fails.由于对 Lambda 的 EventBridge 调用是异步的,对于 EventBridge 来说,到达 lambda 就足以将事件视为成功,但是这样一来,一旦 lambda 失败,我就无法跟踪和重试事件。 Anyone know a way to make the EventBridge to the Lamdba request synchronous or another way to be able to Retry the events if the Lambda code fails after the invocation?任何人都知道一种使 EventBridge 与 Lamdba 请求同步的方法,或者如果 Lambda 代码在调用后失败时能够重试事件的另一种方法?

EventBridge guarantees the delivery of the event to the lambda function but is not aware of what happens post that. EventBridge 保证将事件传递到 lambda function 但不知道之后会发生什么。 It's lambda invocation vs lambda execution.这是 lambda 调用与 lambda 执行。 Eventbridge successfully delivered the message to the lambda service, so it's a successful invocation. Eventbridge 已成功将消息传送到 lambda 服务,因此调用成功。

For Lambda, EventBridge calls invokeAsync API. So, if this API sends a success response, EventBridge will assume the delivery was successful.对于 Lambda,EventBridge 调用 invokeAsync API。因此,如果此 API 发送成功响应,EventBridge 将假定传递成功。 Any failures within Lambda from async to sync is not visible to EventBridge. EventBridge 看不到 Lambda 内从异步到同步的任何失败。 We should configure retries and create DLQs in our Lambda functions to make sure the events are not lost in case the Lambda function fails to execute.我们应该在 Lambda 函数中配置重试并创建 DLQ,以确保在 Lambda function 执行失败时事件不会丢失。 We could in fact configure the same DLQ used by the EventBridge to be used by the Lambda as well so that all eventual failures land in a single place.实际上,我们可以将 EventBridge 使用的相同 DLQ 配置为 Lambda 使用,以便所有最终故障都集中在一个地方。

AWS has a dedicated documentation page for this, which states the following for asynchronous invocation : AWS 为此提供了一个专门的文档页面,其中针对异步调用说明了以下内容:

Lambda retries function errors twice. Lambda 重试 function 错误两次。 If the function doesn't have enough capacity to handle all incoming requests, events might wait in the queue for hours or days to be sent to the function.如果 function 没有足够的容量来处理所有传入请求,则事件可能会在队列中等待数小时或数天才能发送到 function。 You can configure a dead-letter queue on the function to capture events that weren't successfully processed.您可以在 function 上配置死信队列来捕获未成功处理的事件。 For more information, see Asynchronous invocation.有关更多信息,请参阅异步调用。

So that means that as long as your Lambda functions handler function does return an error, the AWS Lambda service should retry to run your Lambda again.这意味着只要您的 Lambda 函数处理程序 function 确实返回错误,AWS Lambda 服务应该重试运行您的 Z04A7DA3C53B048DAZA7DA3C5B04CAD85DA1EEBB92315B8BZ 再次

Therefore, you might not need EventBridge to retry your event.因此,您可能不需要 EventBridge 来重试您的事件。

See: Error handling and automatic retries in AWS Lambda请参阅: AWS Lambda 中的错误处理和自动重试

one option is to make the SQS to be rule target and use SQS event to trigger the lambda.一种选择是使 SQS 成为规则目标并使用 SQS 事件来触发 lambda。 when failure occurs, the lambda won't flag the event done so as to keep the event in the SQS.发生故障时,lambda 不会标记事件已完成,以便将事件保留在 SQS 中。 retry will auto happen after a configured period (SQS configuration).重试将在配置的时间段后自动发生(SQS 配置)。 also you can configure dead letter queue after the retention time expires您也可以在保留时间到期后配置死信队列

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

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