Skip to content

Step Functions JSONATA- Wait Time does not accept variable "seconds - state input" variable

0

Hello Team,

Step-functions wait time feature in JSON-PATH accepts seconds which can be a variable based on state-input, while JSONATA is not supporting that feature, is there any plan to include that ?

asked a year ago253 views
3 Answers
1

Hi,

Are you referring to using the output from another state as an input parameter to define the wait time? If that's the case, check out the following code. I've tested it with an AWS Express Step Function.

{
  "QueryLanguage": "JSONata",
  "Comment": "A description of my state machine",
  "StartAt": "Initialization",
  "States": {
    "Initialization": {
      "Type": "Pass",
      "Next": "Wait",
      "Output": {
        "waitSeconds": 1
      }
    },
    "Wait": {
      "Type": "Wait",
      "Seconds": "{% $states.input.waitSeconds %}",
      "End": true
    }
  }
}
EXPERT
answered 10 months ago
0

Thank you for your question about Step Functions and JSONata. You're correct that there's a difference in how wait times are handled between JSONPath and JSONata in AWS Step Functions.

In JSONPath-based states, you can indeed use variables based on state input to specify wait times in the Wait state. However, it's important to note that Step Functions has recently introduced variables and JSONata as new features to manage state and transform data, which changes how some operations are performed.

While JSONata offers more capabilities compared to JSONPath within Step Functions, including advanced data manipulation and transformation, the current implementation does not directly support using variables for wait times in the same way as JSONPath.

However, JSONata does provide more functions and operators than JSONPath and intrinsic functions in Step Functions. This means that while the exact syntax for specifying wait times might be different, you may be able to achieve similar functionality using JSONata's advanced features.

As for plans to include direct support for variables in wait times using JSONata, AWS has not publicly announced any specific plans for this feature. AWS regularly updates and improves its services based on customer feedback and needs, so it's possible that this functionality could be added in the future.

In the meantime, you might want to explore alternative approaches using JSONata's existing capabilities to achieve your desired workflow. If this functionality is critical for your use case, you may want to consider using JSONPath for the specific states that require variable-based wait times, as Step Functions allows you to use different query languages at the task level.

For the most up-to-date information on Step Functions features and capabilities, it's always best to check the official AWS documentation or reach out to AWS support for specific feature requests or workarounds.

Sources
Simplifying developer experience with variables and JSONata in AWS Step Functions | AWS Compute Blog
What is Step Functions? - AWS Step Functions

answered a year ago
0

Just a note to confirm that Mikel Del Tio's answer works:

"Wait": {
  "Type": "Wait",
  "QueryLanguage": "JSONata",
  "Seconds": "{% $states.input.waitSeconds %}"
}

Note that you can also reference a $variable from the Assign expression of an earlier state.

Wouldn't it be amazing if we could also write…

"SampleChoiceState": {
  "Type": "Choice",
  "QueryLanguage": "JSONata",
  "Choices": [
    {
      "Condition": "{% CONDITION_A %}",
      "Next": "{% $nextStateA %}"
    },
    ...

(Of course I can see why AWS doesn't allow it.)

answered 4 months 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.