0

I have a step function definition as below:

{
    "StartAt": "Assign Variables",
    "QueryLanguage": "JSONata",
    "States": {
        "Assign Variables": {
            "Comment": "Assign variables from input",
            "Type": "Pass",
            "Assign": {
                "var1": "{% $states.input.var1 %}",
                "var2": "{% $states.input.var2 %}"
            },
            "Next": "Parallel_Execution"
        },
        "Parallel_Execution": {
            "Type": "Parallel",
            "Branches": [
                {
                    "StartAt": "Task_A",
                    "States": {
                        "Task_A": {
                            "Comment": "Invoke Lambda Function A to update db",
                            "Type": "Task",
                            "Resource": "arn:aws:lambda:region:account-id:function:FunctionA",
                            "Assign": {
                                **"st_time": "{% $states.result.st_time %}"**
                            },
                            "Next": "Task_B"
                        },
                        "Task_B": {
                            "Comment": "Invoke Lambda Function B to send notification",
                            "Type": "Task",
                            "Resource": "arn:aws:lambda:region:account-id:function:FunctionB",
                            "End": true
                        }
                    }
                }
            ],
            "Catch": [
                {
                    "ErrorEquals": ["States.ALL"],
                    "Next": "Error_Handler"
                }
            ],
            "End": true
        },
        "Error_Handler": {
            "Comment": "Update db to reflect error in above process",
            "Type": "Task",
            "Resource": "arn:aws:lambda:region:account-id:function:ErrorHandlerFunction",
            "Next": "Final_State"
        },
        "Final_State": {
            "Type": "Fail"
        }
    }
}

In the "Error_Handler" state, I need to access the variable "st_time" assigned inside parallel execution using JSONata syntax. I am new to the step function and so to JSONata. So I am not sure how can I achieve this.

1 Answer 1

0
In Step Functions, variables assigned inside Parallel and Map states are scoped to their respective branches and aren't directly accessible outside. Here are a way to handle your requirement:

Pass the variable through the output:
   - Modify Task_A to include st_time in its output
   - Make sure the Parallel state's output includes this value
   - Then you can access it in Error_Handler using:
   `$.Parallel_Execution[0].st_time` (assuming it's in the first branch)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.