I am trying to add error handling in my step function flow using the Parallel and Catch blocks as defined in the State Machine Language.
Following is the flow diagram of my step functions:
Since I want a common error handler for all the step functions, I have wrapped them in a Parallel block and added a common Catch block to catch any errors in any of the step functions. On looking through various examples and blogs, I followed this link and implemented a similar approach.
What I observe is that, whenever any state raises an exception, the control goes into the catch block. The input to the catch block is the exception that was raised containing an Error and Cause in a JSON object. Since I wanted the error along with the input that was passed to that state, I added the ResultPath as "$.error" in the catch block. Following is the JSON spec that defines the state machine.
{
"StartAt": "Try",
"States": {
"Try": {
"Type": "Parallel",
"Branches": [
{
"StartAt": "Step-1",
"States": {
"Step-1": {
"Type": "Task",
"Resource": "arn:aws:lambda:eu-west-1:1234:function:step-1-lambda",
"Next": "Step-2"
},
"Step-2": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.some_variable",
"StringEquals": "some_string",
"Next": "Step-3"
},
{
"Variable": "$.some_variable",
"StringEquals": "some_other_string",
"Next": "Step-4"
}
],
"Default": "Step-6"
},
"Step-3": {
"Type": "Task",
"Resource": "arn:aws:lambda:eu-west-1:1234:function:step-3-lambda",
"Next": "Step-6"
},
"Step-4": {
"Type": "Task",
"Resource": "arn:aws:lambda:eu-west-1:1234:function:step-4-lambda",
"Next": "Step-6"
},
"Step-6": {
"Type": "Task",
"Resource": "arn:aws:lambda:eu-west-1:1234:function:step-6-lambda",
"End": true
}
}
}
],
"Catch": [
{
"ErrorEquals": [
"States.ALL"
],
"ResultPath": "$.error",
"Next": "ErrorHandler"
}
],
"Next": "UnwrapOutput"
},
"UnwrapOutput": {
"Type": "Pass",
"InputPath": "$[0]",
"End": true
},
"ErrorHandler": {
"Type": "Task",
"Resource": "arn:aws:lambda:eu-west-1:1234:function:step-7-lambda",
"End": true
}
}
}
For example, consider that Step-4 generates an exception. The input to this state is:
{
"foo": "abc",
"bar": "def"
}
The input with which the state machine is triggered is:
{
"boo": "jkl",
"baz": "mno"
}
In the ErrorHandler, as Step-4 generates an exception I was expecting that the input to the ErrorHandler state would be:
{
"foo": "abc",
"bar": "def",
"error": {
"Error": "SomeError",
"Cause": "SomeCause"
}
}
However, the input received consists of the original input that is used to trigger the flow.
{
"boo": "jkl",
"baz": "mno",
"error": {
"Error": "SomeError",
"Cause": "SomeCause"
}
}
I need to access the input fields of the state that caused the exception in the ErrorHandler. Using "$" it provides the input that was used to trigger the flow. Is there a way I can achieve this?
Any help would be appreciated, I am trying to figure this out since a long time.

I'm only 10 months late, not that much haha but I hope you have already found a solution for this, In any case, I will share my two cents so I can help another dev, or even better, someone can show me a better way to do this!
First, let's see what scenarios we have:
Our goal: To access the job that triggered the error somehow
First solution - Apply for all scenarios:
Second solution - Apply to Sych jobs execution
When you add an "addCatch" in your state machine, the default behavior it's the error output to overwrite the step input. To solve this you only need to change the addCatch resultPath, this way you will store the error output alongside the step input.
EX: "Catch": [ { "ErrorEquals": [ "States.All" ], "Next": "ErrorHandler" "ResultPath": "$.error-info" } ]
But Why this is important??????
Third Solution -- Apply to Asynch jobs execution
Without any abstraction it would be something like this "USING CDK"
But I also created an abstraction "ParallelStateMachineCatch" so you can use just like this:
}
Here's the ParallelStateMachineCatch code:
Anyway, I hope I can help someone with this, that's how I managed to solve this issue. Please, feel free to teach me better ways! Tks Good Luck and Good Code