Search code examples
amazon-web-servicesaws-step-functions

Propogating error message through Fail state in aws Step Functions


I am using aws Step Functions to manage a workflow. I am using Fail states to handle errors within the workflow. I would like to propagate some of the json from the Step Function workflow so that a user can easily identify the source of their error. So for example, if the json input to a Fail state looked like this:

{
    "error": "some error text",
    "other_stuff": {...}
}

Then I would like to pull the source of the error. I have set up my Fail state like so:

FailState:
    Type: Fail
    Cause: States.Format($.error)
    Error: Failure Here

However, this simply produces the literal string States.Format($.error) as the Cause for the Fail state. How can I use aws states language and the Fail state to show the actual error as a part of the output of the Fail state? Any solution that can successfully propagate the error text from Step Input to Step Output for the Fail state would be sufficient to solve this problem.


Solution

  • The latest update to Step Functions (September 2023) has this feature.

    You can use JsonPath or Intrinsic Functions to create the Error and Cause dynamically:

    "Fail": {
      "Type": "Fail",
      "Comment": "my error comment",
      "ErrorPath": "$.Error",
      "CausePath": "States.Format('this is the error: {}, and this is the cause: {}', $.Error, $.Cause)"
    }
    

    Full documentation here: https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-fail-state.html