- Newest
- Most votes
- Most comments
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
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:
-
In your Catch block, instead of using ResultPath, you'll use the Assign field with JSONata.
-
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.
- 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
Relevant content
- asked 6 months ago
- asked 12 days ago