简体   繁体   English

与AWS Lambda重试失败功能相关的成本?

[英]Costs related to AWS Lambda retrying failing function?

I'm looking into serverless technology (specifically, Python, Django and Zappa on AWS Lambda) and one thing about error handling struck me. 我正在研究无服务器技术(特别是AWS Lambda上的Python,Django和Zappa ),关于错误处理的一件事让我感到震惊。 In the Zappa docs it says 在Zappa文档中它说

By default, AWS Lambda will attempt to retry an event based (non-API Gateway, eg CloudWatch) invocation if an exception has been thrown. 默认情况下,如果抛出异常,AWS Lambda将尝试重试基于事件(非API网关,例如CloudWatch)的调用。

In the AWS Lambda documentation , I read: AWS Lambda文档中 ,我读到:

Depending on the event source, AWS Lambda may retry the failed Lambda function. 根据事件源,AWS Lambda可能会重试失败的Lambda函数。 For example, if Kinesis is the event source, AWS Lambda will retry the failed invocation until the Lambda function succeeds or the records in the stream expire. 例如,如果Kinesis是事件源,则AWS Lambda将重试失败的调用,直到Lambda函数成功或流中的记录到期。

Does this mean a function will be called an infinite number of times when it raises an unhandled exception? 这是否意味着当一个函数引发未处理的异常时,它将被无限次调用? If this goes on unchecked, the costs must go through the roof. 如果不加以控制,成本必须通过屋顶。

Related to that; 与此相关; what is meant by "until the records in the stream expire"? 什么是“直到流中的记录到期”? What records, and what stream? 什么记录,什么流?

According with AWS docs : 根据AWS文档

  • Event sources that aren't stream-based : like S3, API Gateway, etc. 非基于流的事件源 :如S3,API网关等。

    • Synchronous invocation : if you have invoked the Lambda using the SDK or API Gateway, if an exception occurs, you will be responsible to decide if/when/how the request should be retried. 同步调用 :如果您使用SDK或API网关调用了Lambda,如果发生异常,您将负责决定是否/何时/如何重试请求。

    • Asynchronous invocation : if the Lambda was triggered through an async invocation (like S3), it will automatically retry the invocation twice, with delays between retries. 异步调用 :如果Lambda是通过异步调用(如S3)触发的,它将自动重试调用两次,重试之间会有延迟。 If you have specified a Dead Letter Queue, then the failed event is sent to SQS/SNS. 如果您指定了死信队列,则失败的事件将发送到SQS / SNS。 If DLQ was not specified, the event will be discarded. 如果未指定DLQ,则将丢弃该事件。

  • Stream-based event sources : like DynamoDB and Kinesis. 基于流的事件源 :如DynamoDB和Kinesis。

    • If a Lambda function fails, it will continue to try until the data expires (max of 7 days for Kinesis). 如果Lambda函数失败,它将继续尝试直到数据到期(Kinesis最多7天)。 It retries following a exponential backoff with the ceiling of 1 minute between two retries. 它在指数退避后重试,两次重试之间的上限为1分钟。 You will pay for all retries, but you can create an alert to trigger and stop the stream when the source is offline. 您将为所有重试付费,但您可以创建警报以在源脱机时触发和停止流。

The documentation regarding the stream-based event source is not very accurated, but you can read this thread in AWS forums where an AWS employee has answered a question about this: 有关基于流的事件源的文档不是很准确,但您可以在AWS论坛中阅读此线程 ,其中AWS员工已回答了有关此问题的问题:

Question : 问题

Specifically, when my Lambda is getting Kinesis events and writing the data to another service... but the other service goes down for a period of time (eg, a few hours)... is my Lambda going to keep getting called (and throwing errors) at a constant rate? 具体来说,当我的Lambda获得Kinesis事件并将数据写入另一个服务时...但是其他服务停止了一段时间(例如,几个小时)......我的Lambda将继续被调用(和以恒定的速度投掷错误?

Lambda retry is good because I want guaranteed delivery of events, but ideally in this situation, I also don't want to be billed at a high rate when my Lambda becomes consistently UNsuccessful for a time Lambda重试很好,因为我希望保证交付事件,但理想情况是在这种情况下,我也不希望在我的Lambda一直成功一次成功时收取高额费用

Answer : 答案

If the function starts executing but fails because of a downstream dependency, then you do get billed for the duration the function ran. 如果函数开始执行但由于下游依赖性而失败,那么您将在函数运行的持续时间内收费。 Lambda exponentially backs off in case your function fails, up to about one minute. 如果您的功能失败,Lambda会以指数方式退出,最多约一分钟。 You can also monitor this as the ShardIteratorAge increases, and take action to pause your stream processing if needed till you resolve the downstream dependency 您还可以在ShardIteratorAge增加时监视此情况,并在需要时执行暂停流处理的操作,直到您解决下游依赖关系

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

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