Skip to content

Conversation

ginjups
Copy link
Contributor

@ginjups ginjups commented Aug 13, 2025

Issue #, if available:

Description of changes:

Adding a new workflow of JSONata type that demonstrates practical solutions for fetching failed state name in JSONata StateMachine with common fallback state for multiple task states. AWS Step Functions users commonly seek to implement centralized error reporting within their workflows to avoid duplicating error handling logic across multiple states. While implementing a shared error reporting task is straightforward, a significant challenge arises: the error reporting task can access the error message from the failed state, but cannot inherently determine which specific state triggered the error.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@@ -0,0 +1,116 @@
{
"Comment": "StateMachine using JSONata QueryLanguage with common fallback state for multiple task states",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Comment": "StateMachine using JSONata QueryLanguage with common fallback state for multiple task states",
"Comment": "State machine using JSONata query language with common fallback state for multiple task states",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

"End": true
}
},
"QueryLanguage": "JSONata"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to top, just to be more visible

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to top

@@ -0,0 +1,66 @@
# Common Fallback State - JSONata
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would maybe "Shared Fallback State" be a better description?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated Title

@@ -0,0 +1,69 @@
{
"title": "Common Fallback State JSONata",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use same title as in the README

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

"introBox": {
"headline": "How it works",
"text": [
"This example workflow illustrate practical solutions for fetching failed state name in JSONata StateMachine with common fallback state for multiple task states. AWS Step Functions users commonly seek to implement centralized error reporting within their workflows to avoid duplicating error handling logic across multiple states. While implementing a shared error reporting task is straightforward, a significant challenge arises: the error reporting task can access the error message from the failed state, but cannot inherently determine which specific state triggered the error. This limitation becomes particularly problematic in workflows containing numerous Lambda functions, as it complicates identifying the exact point of failure. Using JSONata as our query language, we demonstrate approach to overcome this limitation, enabling comprehensive error tracking while maintaining workflow efficiency."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit too verbose, condense and leave out filler words like "practical", "particular", "comprehensive" etc.
Make the same changes to the README

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-written the explanation

"cleanup": {
"headline": "Cleanup",
"text": [
"1. Delete the stack: <code>sam delete</code>."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"1. Delete the stack: <code>sam delete</code>."
"Delete the stack: <code>sam delete</code>."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


The workflow doesn't require any input. By default, the third lambda function in "ThirdLambdaState" task state is programmed to fail. Thus, the workflow execution fails at this task state and transitions into "FallbackState" with input as "FailedStateName": "ThirdLambdaState".

The "ThirdLambdaFunction" is intentionally programmed to simulate the failure.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add to paragraph above and then remove

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completed


## Testing

To test the workflow, simply start an execution of the state machine. This workflow doesn't require any input payload. Observe the execution once it has completed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please include a description of what the user should expect

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, added


1. Delete the stack
```bash
aws cloudformation delete-stack --stack-name STACK_NAME
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You deployed using SAM, why not use sam delete?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, used sam delete

aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'STACK_NAME')].StackStatus"
```
----
Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@ginjups
Copy link
Contributor Author

ginjups commented Aug 25, 2025

Published the commit 6d22f67 including all the above changes suggested. Thank you!

Copy link
Contributor

@bfreiberg bfreiberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, one minor change and we are ready

@bfreiberg
Copy link
Contributor

Looks good, thanks for your contribution. Your submission will be merged to Serverlessland soon

@julianwood julianwood merged commit 1feff72 into aws-samples:main Aug 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants