AWS Step Functions Enhancements: JSONata and Variables Support

AWS Step Functions recently introduced support for JSONata and variables, simplifying workflow management for developers. These updates eliminate the need for cumbersome JSONPath and complex data-passing tricks between steps, making workflows more efficient.

You Should Know:

  1. JSONata Integration: JSONata is a powerful query and transformation language for JSON data. It allows you to extract and manipulate data more intuitively than JSONPath. For example:
    {
    "input": {
    "user": {
    "name": "John",
    "age": 30
    }
    },
    "output": {
    "fullName": "$.input.user.name",
    "isAdult": "$.input.user.age > 18"
    }
    }
    

  2. Variables Support: Variables simplify passing data between states in a Step Function. Instead of using complex JSONPath expressions, you can now define variables directly:

    {
    "Comment": "A simple example using variables",
    "StartAt": "State1",
    "States": {
    "State1": {
    "Type": "Pass",
    "Result": "Hello",
    "ResultPath": "$.greeting",
    "Next": "State2"
    },
    "State2": {
    "Type": "Pass",
    "Parameters": {
    "message": "World",
    "greeting.$": "$.greeting"
    },
    "End": true
    }
    }
    }
    

  3. Practical Example: Here’s how you can use JSONata and variables together in a Step Function:

    {
    "StartAt": "ExtractData",
    "States": {
    "ExtractData": {
    "Type": "Pass",
    "Parameters": {
    "user": {
    "name": "John",
    "age": 30
    }
    },
    "ResultPath": "$.userData",
    "Next": "TransformData"
    },
    "TransformData": {
    "Type": "Pass",
    "InputPath": "$.userData",
    "Parameters": {
    "fullName.$": "$.user.name",
    "isAdult.$": "$.user.age > 18"
    },
    "End": true
    }
    }
    }
    

  4. AWS CLI Command: To deploy a Step Function using AWS CLI:

    aws stepfunctions create-state-machine --name "MyStateMachine" --definition file://state-machine-definition.json --role-arn arn:aws:iam::123456789012:role/service-role/StepFunctions-MyStateMachine-role
    

  5. Terraform Example: Automate Step Function creation using Terraform:

    resource "aws_sfn_state_machine" "sfn_state_machine" {
    name = "MyStateMachine"
    role_arn = aws_iam_role.step_function_role.arn
    definition = jsonencode({
    "StartAt": "State1",
    "States": {
    "State1": {
    "Type": "Pass",
    "Result": "Hello",
    "Next": "State2"
    },
    "State2": {
    "Type": "Pass",
    "Result": "World",
    "End": true
    }
    }
    })
    }
    

What Undercode Say:

The of JSONata and variables in AWS Step Functions marks a significant improvement in workflow management. These features reduce complexity, enhance readability, and streamline data transformation and passing between states. By leveraging these updates, developers can build more efficient and maintainable workflows. For further reading, check out the official AWS documentation.

References:

Reported By: Darryl Ruggles – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅

Join Our Cyber World:

💬 Whatsapp | 💬 TelegramFeatured Image

Scroll to Top