samxiao
samxiao

Reputation: 2667

Retry and Catch on AWS Step Function task

For StepFunctions, can we have both Retry and Catch working together on the exhausted case?

Here is my use case

  1. Job fails
  2. Retry
  3. Retries exhausted, goes to Catch
  4. Catch all errors, move to next job, and update the DB table to mark this job failed (another task)
  5. Or on success from 1st time run or retries, move to the next job
    "ExecuteMyJob": {
            "Type": "Task",
            "Resource": "arn:aws:states:::glue:startJobRun.sync",
            "Parameters": {
                "JobName.$": "$.jobName",
                "Arguments.$": "$.jobArguments"
            },
            "Retry" : [{
                "ErrorEquals": [ "States.TaskFailed", "States.Runtime" ],
                "MaxAttempts": 3,
                "IntervalSeconds": 60,
                "BackoffRate": 2
            }],
            "Catch": [{
                "ErrorEquals": [ "States.ALL" ],
                "Next": "MarkJobFailOnDbTable"
            }],
            "Next": "NextJobOnPreviousSuccess"
        }

Upvotes: 5

Views: 5607

Answers (1)

Pooya Paridel
Pooya Paridel

Reputation: 1391

Step Functions lets you have both Retry and Catch together:

https://docs.aws.amazon.com/step-functions/latest/dg/concepts-error-handling.html

The Complex retry scenarios example in that link is similar to your example:

"X": {
   "Type": "Task",
   "Resource": "arn:aws:states:us-east-1:123456789012:task:X",
   "Next": "Y",
   "Retry": [ {
      "ErrorEquals": [ "ErrorA", "ErrorB" ],
      "IntervalSeconds": 1,
      "BackoffRate": 2.0,
      "MaxAttempts": 2
   }, {
      "ErrorEquals": [ "ErrorC" ],
      "IntervalSeconds": 5
   } ],
   "Catch": [ {
      "ErrorEquals": [ "States.ALL" ],
      "Next": "Z"
   } ]
}

Upvotes: 5

Related Questions