amazon-web-servicesaws-cdkaws-step-functionsretrypolicy

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. 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?


Solution

  • I found the answer in the documentation There is a flag you can set when you create the LambdaInvoke task called retryOnServiceExceptions. Setting that to false removes the default retry policy.

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