Skip to content

Add Step Functions support for Variables and JSONata features #11906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 22, 2024

Conversation

dominikschubert
Copy link
Member

Motivation

The AWS Step Functions API and Amazon States Language (ASL) have newly introduced support for the following features:

  • The JSONata query and transformation language as an alternative to JSONPath.
  • Workflow variables that allow the ability to assign and reference variables in ASL.

Changes

JSONata

  • Step Function definitions can now use a QueryLanguage field to specify whether to evaluate expressions using JSONata or JSONPath (default). This can be set at the:
    • Top-level, setting the entire state machine's query language.
    • State-level, setting the current state's query language.
  • Strings values surrounded by {% %} will be evaluated as JSONata where present as the value of a non-Path ASL field, a JSON object field, or a JSON array element.
  • The Arguments and Output fields replace usage of the input and output Path fields in JSONPath (InputPath, Parameters, ResultSelector, ResultPath, and OutputPath).
  • Path versions of fields are not supported, where JSONata enclosed expressions should be used instead.
  • Step Functions will reserve a read-only JSONata variable called $states with the following values:
    • $states.input: A state's raw input
    • $states.result: An API or sub-workflow's result (if successful)
    • $states.errorOutput: An error output (only available in Catch)
    • $states.context: The context object
  • The Map state Items field has been added that accepts a JSON array or a JSONata expression that must evaluate to an array.
  • The Choice state Condition field for choice rules that accepts a boolean constant or a JSONata expression that must evaluate to a boolean.
  • Step Functions provides access to the built-in JSONata function library can be used when defining expressions. This replaces the usage of Step Functions' intrinsic functions.

Worfklow Variables

  • Variables can be assigned in JSONata or JSONPath states using the new Assign field.
  • Once assigned, workflow variables can be referenced anywhere (with some exceptions due to scoping and the order of evaluation) using the $ prefix. For example, an assigned variable foo can be accessed with a $ like $foo.
    • A JSONata reference will require the {% %} to enclose the statement i.e
      "Seconds": "{% $foo %}",
      
    • A JSONPath reference will require the ASL field to include a .$ suffix to follow the field name i.e
      "SecondsPath.$": "$foo",
      
      However, this is not required for InputPath, ResultSelector, ResultPath, and OutputPath.

@dominikschubert dominikschubert marked this pull request as ready for review November 22, 2024 17:44
@dominikschubert dominikschubert added the semver: patch Non-breaking changes which can be included in patch releases label Nov 22, 2024
@dominikschubert dominikschubert merged commit 3bfb64b into master Nov 22, 2024
16 of 18 checks passed
dominikschubert pushed a commit that referenced this pull request Nov 22, 2024
Co-authored-by: Greg Furman <31275503+gregfurman@users.noreply.github.com>
@dominikschubert dominikschubert deleted the sfn/variables-n-jsonata branch November 22, 2024 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver: patch Non-breaking changes which can be included in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants