Try-Catch in AWS Step Functions

AWS Step Functions provide Retry and Catch fields to handle errors for individual tasks; however, what if you want to apply a try-catch pattern to several states at once?

Does AWS provide this functionality? Kinda.

A try/catch block, in a development language, assumes that all the execution steps can be "grouped" under a try clause:

try {
    taskOne();
    taskTwo();
    taskThree();
} catch ('States.ALL') {
    alertFailure();
    throw new Error();
}
notifySuccess()

In Step Functions, tasks can be grouped using a parallel state branch.

Following that logic, we can nest the tasks under a branch:

{
  "StartAt": "Try",
  "States": {
        "Try": {
            "Type": "Parallel",
            "Branches": [
                {
                    "StartAt": "TaskOne",
                    "States": {
                        "TaskOne": {
                            "Type": "Pass",
                            "Next": "TaskTwo"
                        },
                        "TaskTwo": {
                            "Type": "Pass",
                            "Next": "TaskThree"
                        },
                        "TaskThree": {
                            "Type": "Pass",
                            "End": true
                        }
                    }
                }
            ],
            "Catch": [
                {
                    "ErrorEquals": [ "States.ALL" ],
                    "Next": "AlertFailure"
                }
            ],
            "Next": "NotifySuccess"
        },
        "AlertFailure": {
            "Type": "Pass",
            "Next": "Fail"
        },
        "Fail": {
            "Type": "Fail"
        },
        "NotifySuccess": {
            "Type": "Pass",
            "End": true
        }
    }
}

Additionally, there is one consideration: a parallel state encapsulates the branch outputs into an array. To extract the output, add another Pass state:

"ExtractOutput": {
    "Type": "Pass",
    "InputPath": "$[0]",
    "Next": "NotifySuccess"
}

Final StepFunction

{
  "StartAt": "Try",
  "States": {
        "Try": {
            "Type": "Parallel",
            "Branches": [
                {
                    "StartAt": "TaskOne",
                    "States": {
                        "TaskOne": {
                            "Type": "Pass",
                            "Next": "TaskTwo"
                        },
                        "TaskTwo": {
                            "Type": "Pass",
                            "Next": "TaskThree"
                        },
                        "TaskThree": {
                            "Type": "Pass",
                            "End": true
                        }
                    }
                }
            ],
            "Catch": [
                {
                    "ErrorEquals": [ "States.ALL" ],
                    "Next": "AlertFailure"
                }
            ],
            "Next": "ExtractOutput"
        },
        "AlertFailure": {
            "Type": "Pass",
            "Next": "Fail"
        },
        "Fail": {
            "Type": "Fail"
        },
        "ExtractOutput": {
            "Type": "Pass",
            "InputPath": "$[0]",
            "Next": "NotifySuccess"
        },
        "NotifySuccess": {
            "Type": "Pass",
            "End": true
        }
    }
}