I am wondering how to access the cause of my custom exception raised inside my lambda function. I need to access it at the end of my Step Functions workflow, as shown below.
The diagram below is an example of a failed execution. The error (error-info
object, with its' own Error
and Cause
sections) is found in the output of ParseTextractOutput
, but I am wondering how to access it in OutputNotFound
as shown below.
Step Functions Diagram
Output
The output of ParseTextractOutput
is
{
"event"...
"error-info": {
"Error": "OutputNotFoundException",
"Cause": "{\"errorMessage\": \"Contents of Textracted file: {...}}"
}
}
}
I'd like to access this data somehow in these fields (of the Step Functions definition):
...
"States": {
"OutputNotFound": {
"Type": "Fail",
"Error": "<useful stuff here, like $.error-info.Error or something>",
"Cause": "<useful stuff here, like $.error-info.Cause or something>"
},
...
"ParseTextractOutput": {
"Type": "Task",
"Resource": "functionARN",
"Catch": [
{
"ErrorEquals": ["OutputNotFoundException"],
"ResultPath": "$.error-info",
"Next": "OutputNotFound"
}
],
"End": true
}
Python Code
Here's the relevant code for the Function ParseTextractOutput
.
class OutputNotFoundException(Exception):
pass
...
try:
blocks = data['Blocks']
except KeyError as e:
raise OutputNotFoundException('Contents of Textracted file: {}'.format(data))
Type
andComments
field. As you needInputPath
to access the variables from the previous state. You can do a workaround by creating a Choice state after ParseTextractOutput based on the result you can either go to Fail state or Succeed state. – Farver