了解 AWS lambda 重试机制
Understanding AWS lambda retry mechanism
我的用例:
从 spring-boot 应用程序,我将有效负载发布到 AWS SNS,此 SNS 正在触发 Lambda 函数。
如果 lambda 函数失败,AWS lambda 上是否有可用的配置,我们可以在其中指定重试次数和每次重试发生的持续时间?
遗憾的是,你无法控制retry policies as explained in the docs:
With the exception of HTTP/S, you can't change Amazon SNS-defined delivery policies.
https://docs.aws.amazon.com/sns/latest/dg/sns-message-delivery-retries.html 指定 Lambda 的重试策略:
Immediate retry (no delay) phase
Pre-backoff phase
Backoff phase
Post-backoff phase
Total attempts
3 times, without delay
2 times, 1 second apart
10 times, with exponential backoff, from 1 second to 20 seconds
100,000 times, 20 seconds apart
100,015 times, over 23 days
还有笔记
With the exception of HTTP/S, you can't change Amazon SNS-defined delivery policies. Only HTTP/S supports custom policies. See Creating an HTTP/S delivery policy.
因此否,您无法更改 SNS 对 Lambda 调用的重试行为。您可以做的是将 SQS 队列订阅到 SNS,然后让您的 lambda 被该队列触发。在 SQS 上,您可以在某种程度上配置重试行为:https://docs.aws.amazon.com/lambda/latest/operatorguide/sqs-retries.html .
我的用例: 从 spring-boot 应用程序,我将有效负载发布到 AWS SNS,此 SNS 正在触发 Lambda 函数。
如果 lambda 函数失败,AWS lambda 上是否有可用的配置,我们可以在其中指定重试次数和每次重试发生的持续时间?
遗憾的是,你无法控制retry policies as explained in the docs:
With the exception of HTTP/S, you can't change Amazon SNS-defined delivery policies.
https://docs.aws.amazon.com/sns/latest/dg/sns-message-delivery-retries.html 指定 Lambda 的重试策略:
Immediate retry (no delay) phase | Pre-backoff phase | Backoff phase | Post-backoff phase | Total attempts |
---|---|---|---|---|
3 times, without delay | 2 times, 1 second apart | 10 times, with exponential backoff, from 1 second to 20 seconds | 100,000 times, 20 seconds apart | 100,015 times, over 23 days |
还有笔记
With the exception of HTTP/S, you can't change Amazon SNS-defined delivery policies. Only HTTP/S supports custom policies. See Creating an HTTP/S delivery policy.
因此否,您无法更改 SNS 对 Lambda 调用的重试行为。您可以做的是将 SQS 队列订阅到 SNS,然后让您的 lambda 被该队列触发。在 SQS 上,您可以在某种程度上配置重试行为:https://docs.aws.amazon.com/lambda/latest/operatorguide/sqs-retries.html .