Convert Step Function Catch ResultPath to Jsonata?

0

Before migrating to Jsonata, our AWS Step Function relied on Catch field's ResultPath in order to include the error as part of the original input, as documented https://docs.aws.amazon.com/step-functions/latest/dg/input-output-resultpath.html#input-output-resultpath-catch:

  • Catch ResultPath Docs

Jsonata has a similar feature here:

  • errorOutput Docs

But how do we use errorOutput so that the Next task called from a Catch contains that error with the original input? I essentially need an equivalency for how Catch ResultPath worked with jsonata.

asked 16 days ago93 views
2 Answers
1
Accepted Answer

I just came across this post while i was looking for an answer. I think i found an easier solution vs using Assign. In the Catch block you can use Output field and jsonata merging. This will merge output to states.input + error and feed this combined object as the Catch "Next" state's input

"Output": "{% $merge([ $states.input, {'error-info': $states.errorOutput} ]) %}"

Refer Jsonata catchers in the ASL specs https://states-language.net/spec.html#fallback-states

answered 16 days ago
profile picture
EXPERT
reviewed 16 days ago
0

To achieve the same functionality as the Catch ResultPath in JSONata for AWS Step Functions, you can use the $states.errorOutput variable along with the $states.input variable. Here's how you can include the error with the original input in the Next task called from a Catch:

  1. In your Catch block, instead of using ResultPath, you'll use the Assign field with JSONata.

  2. Use the following structure in your Assign field:

    "Assign": { "error": "{% $states.errorOutput %}", "input": "{% $states.input %}" }

This will create a new object that includes both the original input and the error information.

  1. In the Next task, you can access this combined information. The error details will be available in the "error" field, and the original input will be in the "input" field.

This approach preserves the original input and includes the error information, similar to how the ResultPath worked in the JSONPath-based approach. The $states.errorOutput variable in JSONata contains the error information when an error occurs, equivalent to the error object in the previous approach.

Remember to set "QueryLanguage": "JSONata" in your state machine definition to use JSONata expressions.

By using this method, you maintain the functionality of including both the error and the original input in your error handling flow, allowing subsequent tasks to access and process this information as needed.
Sources
Specifying state output using ResultPath in Step Functions - AWS Step Functions
Passing data between states with variables - AWS Step Functions

profile picture
answered 16 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions