简体   繁体   English

在 AWS CDK 中设置 state 机器时,如何删除 Lambda 调用的默认重试策略?

[英]When setting up a state machine in the AWS CDK, how do you remove the default Retry policy for a Lambda Invocation?

I'm creating a state machine with the AWS CDK.我正在使用 AWS CDK 创建 state 机器。 Instead of the default retry policy, which looks like this:而不是默认的重试策略,如下所示:

  "Retry": [
    {
      "ErrorEquals": [
        "Lambda.ServiceException",
        "Lambda.AWSLambdaException",
        "Lambda.SdkClientException"
      ],
      "IntervalSeconds": 2,
      "MaxAttempts": 6,
      "BackoffRate": 2
    }
  ]

I want to have only one catch-all policy that looks like this:我只想拥有一个看起来像这样的包罗万象的政策:

"Retry": [
    {
      "ErrorEquals": [
        "States.ALL"
      ],
      "IntervalSeconds": 10,
      "MaxAttempts": 3,
      "BackoffRate": 1.5
    }
  ]

Unfortunately I can't find a way to remove the default policy when deploying the stack.不幸的是,我在部署堆栈时找不到删除默认策略的方法。 My catch-all simply gets added to the end of the Retry policy array.我的包罗万象只是被添加到重试策略数组的末尾。

"Retry": [
    {
      "ErrorEquals": [
        "Lambda.ServiceException",
        "Lambda.AWSLambdaException",
        "Lambda.SdkClientException"
      ],
      "IntervalSeconds": 2,
      "MaxAttempts": 6,
      "BackoffRate": 2
    },
    {
      "ErrorEquals": [
        "States.ALL"
      ],
      "IntervalSeconds": 10,
      "MaxAttempts": 3,
      "BackoffRate": 1.5
    }
  ]

Anyone know how to get rid of the default policy?任何人都知道如何摆脱默认策略?

I found the answer in the documentation There is a flag you can set when you create the LambdaInvoke task called retryOnServiceExceptions .我在文档中找到了答案 当您创建名为retryOnServiceExceptions的 LambdaInvoke 任务时,您可以设置一个标志。 Setting that to false removes the default retry policy.将其设置为 false 会删除默认的重试策略。

var submitOrder = new sfnt.LambdaInvoke(this, "SubmitOrder", {
  lambdaFunction: submitOrderLambda,
  comment: "Call the orders api to submit the order update",
  retryOnServiceExceptions: false   
});

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

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