<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Damien Jones</title>
    <description>The latest articles on DEV Community by Damien Jones (@amazonwebshark).</description>
    <link>https://dev.to/amazonwebshark</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2933230%2F6c34c94f-d507-4a94-a22f-651363bba36b.jpg</url>
      <title>DEV Community: Damien Jones</title>
      <link>https://dev.to/amazonwebshark</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/amazonwebshark"/>
    <language>en</language>
    <item>
      <title>Simplified Data Workflows With AWS Step Functions Variables</title>
      <dc:creator>Damien Jones</dc:creator>
      <pubDate>Sun, 15 Jun 2025 15:07:44 +0000</pubDate>
      <link>https://dev.to/aws-builders/simplified-data-workflows-with-aws-step-functions-variables-3ac3</link>
      <guid>https://dev.to/aws-builders/simplified-data-workflows-with-aws-step-functions-variables-3ac3</guid>
      <description>&lt;p&gt;In this post, I use AWS Step Functions variables and JSONata to create a simplified API data capture workflow with Lambda and DynamoDB.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This post was originally published on &lt;a href="https://amazonwebshark.com/simplified-data-workflows-with-aws-step-functions-variables/" rel="noopener noreferrer"&gt;amazonwebshark.com&lt;/a&gt; on 03 March 2025. Some of the formatting and snippets are best viewed there, although the wording is identical. - Damien&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;I've become an AWS Step Functions convert in recent times. Back in 2020 when I first studied it for some AWS certifications, Step Functions defined workflows entirely in JSON, making it less approachable and often overlooked.&lt;/p&gt;

&lt;p&gt;How times change! With &lt;a href="https://aws.amazon.com/blogs/aws/new-aws-step-functions-workflow-studio-a-low-code-visual-tool-for-building-state-machines/" rel="noopener noreferrer"&gt;2021's inclusion of a visual editor&lt;/a&gt;, Step Functions became far more accessible, helping it become a key tool in serverless application design. And in 2024 two major updates significantly enhanced Step Functions' flexibility: JSONata support, which I recently explored, and built-in variables, which simplify state transitions and data management. This post focuses on the latter.&lt;/p&gt;

&lt;p&gt;To demonstrate the power of Step Functions variables, I'll walk through a practical example: fetching API data, verifying the response, and inserting it into DynamoDB. Firstly, I'll examine the services and features I'll use. Then I'll create a state machine and examine each state's use of variables. Finally, I'll complete some test executions to ensure everything works as expected.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If a 'simplified' workflow seems hard to justify as a 20-minute read...that's fair. But mastering Step Functions variables now can save hours of debugging and development in the long run! - Ed&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Also, special thanks to AWS Community Builder &lt;a href="https://www.linkedin.com/in/md-mostafa/" rel="noopener noreferrer"&gt;Md. Mostafa Al Mahmud&lt;/a&gt; for generously providing AWS credits to support this and future posts!&lt;/p&gt;

&lt;h2&gt;
  
  
  Architecture
&lt;/h2&gt;

&lt;p&gt;This section provides a top-level view of the architecture behind my simplified Step Functions variables workflow, highlighting the main AWS services involved in getting and processing API data. I'll briefly cover the data being used, the role of Step Functions variables and the integration of DynamoDB within the workflow.&lt;/p&gt;

&lt;h3&gt;
  
  
  API Data
&lt;/h3&gt;

&lt;p&gt;The data comes from a RESTful API that provides UK car details. The API needs both an authentication key and query parameters. Response data is provided in JSON.&lt;/p&gt;

&lt;p&gt;The data used in this post is about my car. As some of it is sensitive, I will only use data that is already publicly available:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "make": "FORD",
    "yearOfManufacture": 2014,
    "engineCapacity": 1242,
    "co2Emissions": 120,
    "fuelType": "PETROL",
    "markedForExport": false,
    "colour": "GREY",
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are several data types here. This will be important when writing to DynamoDB!&lt;/p&gt;

&lt;h3&gt;
  
  
  AWS Step Functions Variables
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://amazonwebshark.com/low-code-s3-key-validation-with-aws-step-functions-jsonata/" rel="noopener noreferrer"&gt;In my last post&lt;/a&gt;, I talked about JSONata in AWS Step Functions. This time let's talk about Step Functions variables, which were &lt;a href="https://aws.amazon.com/blogs/compute/simplifying-developer-experience-with-variables-and-jsonata-in-aws-step-functions/" rel="noopener noreferrer"&gt;introduced alongside JSONata in November 2024&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Step Functions variables offer a simple way to store and reuse data within a state machine, enabling dynamic workflows without complex transformations. They work well with both JSONata and JSONPath and are available at no extra cost in all AWS regions that support Step Functions.&lt;/p&gt;

&lt;p&gt;Variables are set using &lt;code&gt;Assign&lt;/code&gt;. They can be assigned static values for &lt;em&gt;fixed&lt;/em&gt; values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Assign": {
    "productName": "product1",
    "count" : 42,
    "available" : true
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As well as dynamic values for &lt;em&gt;changing&lt;/em&gt; values. To dynamically set variables, Step Functions uses JSONata expressions within &lt;code&gt;{% ... %}&lt;/code&gt;. The following example extracts &lt;code&gt;productName&lt;/code&gt; and &lt;code&gt;available&lt;/code&gt; from the state input using the JSONata &lt;code&gt;$states&lt;/code&gt; reserved variable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Assign": {
    "product": "{% $states.input.productName %}",
    "available": "{% $states.input.available %}"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Variables are then referenced using dollar signs (&lt;code&gt;$&lt;/code&gt;), e.g. &lt;code&gt;$productName&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;There's tonnes more to this. For details on name syntax, ASL integration and creating JSONPath variables, check the &lt;a href="https://docs.aws.amazon.com/step-functions/latest/dg/workflow-variables.html" rel="noopener noreferrer"&gt;Step Functions Developer Guide variables section&lt;/a&gt;. Additionally, watch AWS Principal Developer Advocate &lt;a href="https://www.linkedin.com/in/singledigit/" rel="noopener noreferrer"&gt;Eric Johnson&lt;/a&gt;'s related video:&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/1Bc6jqZhUAw"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;With Step Functions variables handling data transformation and persistence, the next step is storing processed data efficiently. This is where Amazon DynamoDB comes in.&lt;/p&gt;

&lt;h3&gt;
  
  
  Amazon DynamoDB
&lt;/h3&gt;

&lt;p&gt;DynamoDB is a fully managed NoSQL database built for high performance and seamless scalability. Its flexible, schema-less design makes it perfect for storing and retrieving JSON-like data with minimal overhead.&lt;/p&gt;

&lt;p&gt;DynamoDB can automatically scale to manage millions of requests per second while maintaining low latency. It integrates seamlessly with AWS services like Lambda and API Gateway, providing built-in security, automated backups, and global replication to ensure reliability at any scale.&lt;/p&gt;

&lt;p&gt;Popular use cases include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Serverless backends (paired with AWS Lambda/API Gateway) for API-driven apps.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Real-time workloads like user sessions, shopping carts, or live leaderboards.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;High-velocity data streams from IoT devices or clickstream analytics.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Diagram
&lt;/h3&gt;

&lt;p&gt;Finally, here is an architectural diagram of my simplified Step Functions variables workflow:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fti8c76wy5dwfcbg6dxoo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fti8c76wy5dwfcbg6dxoo.png" alt="ArchitectureDiagram"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In which:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The user triggers an AWS Step Functions state machine with a JSON key-value pair as input.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A Lambda function is invoked with the input payload.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The Lambda function sends a &lt;code&gt;POST&lt;/code&gt; request to a third-party API.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The API server responds with JSON data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The Lambda function assigns Step Functions variables to store API response values and enters a &lt;code&gt;Choice&lt;/code&gt; state that checks the API response code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If the &lt;code&gt;Choice&lt;/code&gt; state condition &lt;strong&gt;fails&lt;/strong&gt;, SNS publishes a failure notification email.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The state machine terminates with an &lt;code&gt;ExecutionFailed&lt;/code&gt; status.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If the &lt;code&gt;Choice&lt;/code&gt; state condition &lt;strong&gt;passes&lt;/strong&gt;, the processed API response data is written to a DynamoDB table.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;SNS publishes a success notification email.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The state machine terminates with an &lt;code&gt;ExecutionSucceeded&lt;/code&gt; status.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If an error occurs at any point in execution, SNS publishes a failure notification email and the state machine terminates with an &lt;code&gt;ExecutionFailed&lt;/code&gt; status.&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;p&gt;In this section, I create and configure my simplified Step Functions variables workflow resources, which are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;AWS Lambda function&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;AWS Step Functions Choice state&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Amazon DynamoDB table&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Amazon SNS topic&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  AWS Lambda
&lt;/h3&gt;

&lt;p&gt;This section details how I created an AWS Lambda function to interact with a REST API. The function makes a secure &lt;code&gt;POST&lt;/code&gt; request, manages potential errors and parses the response for use in downstream states. Additionally, I will discuss an issue I encountered while attempting to create variables from the function's output using JSONata.&lt;/p&gt;

&lt;h4&gt;
  
  
  Lambda Function
&lt;/h4&gt;

&lt;p&gt;First, I need to write a function. It's nothing special - I have the API link and security key I need, and I just want to retrieve some data. So I decided to give &lt;a href="https://aws.amazon.com/q/developer/" rel="noopener noreferrer"&gt;Amazon Q Developer&lt;/a&gt; a try!&lt;/p&gt;

&lt;p&gt;I used this prompt:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I have an HTTPS hyperlink for a REST API and an API key. I want to send a POST request to the API using the key. I have a USERID parameter that I will pass as JSON.&lt;/p&gt;

&lt;p&gt;Please write a Python function for AWS Lambda with error handling. Please use security best practises and Pythonic standards.&lt;/p&gt;

&lt;p&gt;Yes I do say Please in my prompts.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Amazon Q produced a decent script with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;API endpoint and key stored as environment variables.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use of the &lt;code&gt;requests&lt;/code&gt; module with a timeout to prevent indefinite hangs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Error handling for request failures, validation errors, and unexpected issues.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A structured JSON response including the status code and parsed response.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import json
import os
import logging
import requests
from typing import Dict, Any
from botocore.exceptions import ClientError

# Configure logging
logger = logging.getLogger()
logger.setLevel(logging.INFO)

def lambda_handler(event: Dict[str, Any], context: Any) -&amp;gt; Dict[str, Any]:
    """
    AWS Lambda function to make POST request to API endpoint
    Args:
        event: Lambda event object containing request data
        context: Lambda context object
    Returns:
        API response as dictionary
    """
    try:
        # Get API endpoint and key from environment variables
        api_endpoint = os.environ['API_ENDPOINT']
        api_key = os.environ['API_KEY']

        # Extract user ID from event
        user_id = event.get('userId')
        if not user_id:
            raise ValueError("userId is required in the request")

        # Set request headers
        headers = {
            'Content-Type': 'application/json',
            'x-api-key': api_key
        }

        # Prepare request payload
        payload = {
            'userId': user_id
        }

        # Make POST request
        response = requests.post(
            api_endpoint,
            headers=headers,
            json=payload,
            timeout=30  # Set timeout for the request
        )

        # Raise exception for bad status codes
        response.raise_for_status()

        return {
            'statusCode': response.status_code,
            'body': response.json()
        }

    except requests.exceptions.RequestException as e:
        logger.error(f"API request failed: {str(e)}")
        return {
            'statusCode': 500,
            'body': json.dumps({'error': 'Failed to make API request'})
        }

    except ValueError as e:
        logger.error(f"Validation error: {str(e)}")
        return {
            'statusCode': 400,
            'body': json.dumps({'error': str(e)})
        }

    except Exception as e:
        logger.error(f"Unexpected error: {str(e)}")
        return {
            'statusCode': 500,
            'body': json.dumps({'error': 'Internal server error'})
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It needed some tweaks for my purposes, but was still faster than typing it all out manually!&lt;/p&gt;

&lt;h4&gt;
  
  
  Step Functions Config
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;Lambda: Invoke&lt;/code&gt; action defaults to using the state input as the payload, so &lt;code&gt;"Payload": "{% $states.input %}"&lt;/code&gt; is scripted automatically:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    "Lambda Invoke": {
      "Type": "Task",
      "Resource": "arn:aws:states:::lambda:invoke",
      "Output": "{% $states.result.Payload %}",
      "Arguments": {
        "FunctionName": "[LAMBDA_ARN]:$LATEST",
        "Payload": "{% $states.input %}"
      },
      "Next": "Check API Status Code"
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is going to be helpful in the next section!&lt;/p&gt;

&lt;p&gt;Step Functions manages retries and error handling. If my Lambda function fails, it will retry up to three times with exponential backoff before sending a failure notification through SNS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    "Lambda Invoke": {
      "Retry": [
        {
          "ErrorEquals": [
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "IntervalSeconds": 1,
          "MaxAttempts": 3,
          "BackoffRate": 2,
          "JitterStrategy": "FULL"
        }
      ],
      "Next": "Check API Status Code",
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "SNS Publish: Fail"
        }
      ]
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, let's talk about the function's outputs.&lt;/p&gt;

&lt;h4&gt;
  
  
  Outputs &amp;amp; JSONata Variables
&lt;/h4&gt;

&lt;p&gt;The Lambda function returns a nested JSON structure. Here's a redacted example of it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "output": {
    "ExecutedVersion": "$LATEST",
    "Payload": {
      "statusCode": 200,
      "body": {
        "make": "FORD",
        "yearOfManufacture": 2014,
        "engineCapacity": 1242,
        "co2Emissions": 120,
        "fuelType": "PETROL",
        "markedForExport": false,
        "colour": "GREY"
      }
    },
    "SdkHttpMetadata": {
      "AllHttpHeaders": {
        "REDACTED": "REDACTED"
      },
      "HttpHeaders": {
        "REDACTED": "REDACTED"
      },
      "HttpStatusCode": 200
    },
    "SdkResponseMetadata": {
      "REDACTED": "REDACTED"
    },
    "StatusCode": 200
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I mentioned earlier about &lt;code&gt;Lambda: Invoke&lt;/code&gt;'s default &lt;code&gt;Payload&lt;/code&gt; setting. This default creates a &lt;code&gt;{% $states.result.Payload %}&lt;/code&gt; JSONata expression output that I can use to assign variables for downstream states.&lt;/p&gt;

&lt;p&gt;In this example, &lt;code&gt;{% $states.result.Payload %}&lt;/code&gt; returns this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "Payload": {
      "statusCode": 200,
      "body": {
        "make": "FORD",
        "yearOfManufacture": 2014,
        "engineCapacity": 1242,
        "co2Emissions": 120,
        "fuelType": "PETROL",
        "markedForExport": false,
        "colour": "GREY"
      }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's make a variable for &lt;code&gt;statusCode&lt;/code&gt;. In the response, &lt;code&gt;statusCode&lt;/code&gt; is a property of &lt;code&gt;Payload&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "Payload": {
      "statusCode": 200
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In JSONata this is expressed as &lt;code&gt;{% $states.result.Payload.statusCode %}&lt;/code&gt;. Then I can assign the JSONata expression to a &lt;code&gt;statusCode&lt;/code&gt; variable via JSON. In the AWS console, I do this via:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "statusCode": "{% $states.result.Payload.statusCode %}"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And in Step Functions ASL via:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Assign": {"statusCode": "{% $states.result.Payload.statusCode %}"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I can then call this variable using &lt;code&gt;$statusCode&lt;/code&gt;. Here, this will return &lt;code&gt;200&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Next, let's make a &lt;code&gt;make&lt;/code&gt; variable. This is slightly more involved as &lt;code&gt;make&lt;/code&gt; is a property of &lt;code&gt;body&lt;/code&gt;, which is itself a property of &lt;code&gt;Payload&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "Payload": {
      "body": {
        "make": "FORD"
      }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So this time I need:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CONSOLE:
"make": "{% $states.result.Payload.body.make%}"

ASL:
"Assign": {"make": "{% $states.result.Payload.body.make%}"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And now &lt;code&gt;$make&lt;/code&gt; will return &lt;code&gt;"FORD"&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So let's do the other values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Assign": {
    "statusCode": "{% $states.result.Payload.statusCode %}",
    "make": "{% $states.result.Payload.body.make%}",
    "yearOfManufacture": "{% $string($states.result.Payload.body.yearOfManufacture) %}",
    "engineCapacity": "{% $string($states.result.Payload.body.engineCapacity) %}",
    "co2Emissions": "{% $string($states.result.Payload.body.co2Emissions) %}",
    "fuelType": "{% $states.result.Payload.body.fuelType %}",
    "markedForExport": "{% $states.result.Payload.body.markedForExport%}",
    "colour": "{% $states.result.Payload.body.colour%}"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that variables returning numbers from the response body like &lt;code&gt;yearOfManufacture&lt;/code&gt; have an additional &lt;code&gt;$string&lt;/code&gt; JSONata expression. I'll explain the reason for this in the DynamoDB section.&lt;/p&gt;

&lt;h4&gt;
  
  
  Lambda Issues
&lt;/h4&gt;

&lt;p&gt;When I first started using Step Functions variables, I used a different Lambda function for the API call and kept getting this error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;An error occurred.

The JSONata expression '$states.input.body.make' specified for the field 'Assign/make' returned nothing (undefined).
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After getting myself confused, I checked the function's &lt;code&gt;return&lt;/code&gt; statement and found this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return {
    'statusCode': response.status_code,
    'body': response.text
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;response.text&lt;/code&gt; returns the response body as a JSON-formatted &lt;strong&gt;string&lt;/strong&gt; rather than as a nested &lt;strong&gt;dictionary&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "statusCode": 200,
  "body": "{\"make\":\"FORD\",\"yearOfManufacture\":2014,\"engineCapacity\":1242,\"co2Emissions\":120,\"fuelType\":\"PETROL\",\"markedForExport\":false,\"colour\":\"GREY\"}"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That string isn't compatible with dot notation. So while &lt;code&gt;$states.input.body&lt;/code&gt; will match the whole body, &lt;code&gt;$states.input.body.make&lt;/code&gt; can't match anything because the string can't be traversed. So nothing is returned, causing the error.&lt;/p&gt;

&lt;p&gt;Using &lt;code&gt;response.json()&lt;/code&gt; fixes this, as the response is now correctly structured for JSONata expressions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return {
    'statusCode': response.status_code,
    'body': response.json()
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Choice State
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;Choice&lt;/code&gt; state here is very similar to &lt;a href="https://amazonwebshark.com/low-code-s3-key-validation-with-aws-step-functions-jsonata/#s3-key-itunes-string-check" rel="noopener noreferrer"&gt;a previous one&lt;/a&gt;. This &lt;code&gt;Choice&lt;/code&gt; state checks the Lambda function's API response and routes accordingly.&lt;/p&gt;

&lt;p&gt;Here, the &lt;code&gt;Choice&lt;/code&gt; state uses the JSONata expression &lt;code&gt;{% $statusCode = 200 %}&lt;/code&gt; to check the &lt;code&gt;$statusCode&lt;/code&gt; variable value. By default, it will transition to the &lt;code&gt;SNS Publish: Fail&lt;/code&gt; state. However, if &lt;code&gt;$statusCode&lt;/code&gt; equals &lt;code&gt;200&lt;/code&gt;, then the &lt;code&gt;Choice&lt;/code&gt; state will transition to the &lt;code&gt;DynamoDB PutItem&lt;/code&gt; state instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    "Check API Status Code": {
      "Type": "Choice",
      "Choices": [
        {
          "Next": "DynamoDB PutItem",
          "Condition": "{% $statusCode = 200 %}"
        }
      ],
      "Default": "SNS Publish: Fail"
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This step prevents silent failures by ensuring unsuccessful API responses trigger an SNS notification instead of proceeding to DynamoDB. It also helps maintain data integrity by isolating success and failure paths, and ensuring only valid responses are saved in DynamoDB.&lt;/p&gt;

&lt;p&gt;So now I've captured the data and confirmed its integrity. Next, let's store it somewhere!&lt;/p&gt;

&lt;h3&gt;
  
  
  Amazon DynamoDB
&lt;/h3&gt;

&lt;p&gt;It's time to think about storing the API data. Enter DynamoDB! This section covers creating a table, writing data and integrating DynamoDB with AWS Step Functions and JSONata. I'll share key lessons learned, especially about handling data types correctly.&lt;/p&gt;

&lt;p&gt;Let's start by creating a table.&lt;/p&gt;

&lt;h4&gt;
  
  
  Creating A Table
&lt;/h4&gt;

&lt;p&gt;Before inserting data into DynamoDB, I need to create a table. Since DynamoDB is a schemaless database, all that is required to create a new table is a table name and a primary key. Naming the table is straightforward, so let's focus on the key.&lt;/p&gt;

&lt;p&gt;DynamoDB has two types of key:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Partition key&lt;/strong&gt; &lt;em&gt;(required&lt;/em&gt;): Part of the table's primary key. It's a hash value that is used to retrieve items from the table and allocate data across hosts for scalability and availability.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Sort key&lt;/strong&gt; &lt;em&gt;(optional&lt;/em&gt;): The second part of a table's primary key. The sort key enables sorting or searching among all items sharing the same partition key.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's look at an example using a &lt;strong&gt;Login&lt;/strong&gt; table. In this table, the &lt;strong&gt;user ID&lt;/strong&gt; serves as the &lt;strong&gt;partition&lt;/strong&gt; key, while the &lt;strong&gt;login date&lt;/strong&gt; acts as the &lt;strong&gt;sort&lt;/strong&gt; key. This structure enables efficient lookups and sorting, allowing quick retrieval of a user's login history while minimizing operational overhead.&lt;/p&gt;

&lt;p&gt;To use a physical analogy, consider the DynamoDB table as a &lt;strong&gt;filing cabinet&lt;/strong&gt;, the Partition key as a &lt;strong&gt;drawer&lt;/strong&gt;, and the Sort key as a &lt;strong&gt;folder&lt;/strong&gt;. If I wanted to retrieve &lt;strong&gt;User 123&lt;/strong&gt;'s logins for &lt;strong&gt;2025&lt;/strong&gt;, I would:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Access the &lt;strong&gt;Logins&lt;/strong&gt; filing cabinet (&lt;em&gt;DynamoDB table&lt;/em&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Find User 123's &lt;strong&gt;drawer&lt;/strong&gt; (&lt;em&gt;Partition Key&lt;/em&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Get User 123's 2025 &lt;strong&gt;folder&lt;/strong&gt; (&lt;em&gt;Sort Key&lt;/em&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;DynamoDB provides many features beyond those discussed here. For the latest features, please refer to the &lt;a href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html" rel="noopener noreferrer"&gt;Amazon DynamoDB Developer Guide&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Writing Data
&lt;/h4&gt;

&lt;p&gt;So now I have a table, how do I put data in it?&lt;/p&gt;

&lt;p&gt;DynamoDB offers several ways to write data, and a common one is &lt;code&gt;PutItem&lt;/code&gt;. This lets me insert or replace an item in my table. Here's a basic example of adding a login event to a &lt;code&gt;UserLogins&lt;/code&gt; table:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "TableName": "UserLogins",
    "Item": {
        "UserID": { "S": "123" },
        "LoginDate": { "S": "2025-02-25T12:00:00Z" },
        "Device": { "S": "Laptop" }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;TableName&lt;/code&gt; specifies the &lt;strong&gt;name&lt;/strong&gt; of the DynamoDB table where the item will be stored.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Item&lt;/code&gt; represents the &lt;strong&gt;data&lt;/strong&gt; being inserted into the table. It contains key-value pairs, where the &lt;strong&gt;attributes&lt;/strong&gt; (e.g. &lt;code&gt;UserID&lt;/code&gt;) are mapped to their corresponding &lt;strong&gt;data types&lt;/strong&gt; (e.g. &lt;code&gt;"S"&lt;/code&gt;) and &lt;strong&gt;values&lt;/strong&gt; (e.g. &lt;code&gt;"123"&lt;/code&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;UserID&lt;/code&gt; is an &lt;strong&gt;attribute&lt;/strong&gt; in the item being inserted.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;"S"&lt;/code&gt; is a &lt;strong&gt;data type descriptor&lt;/strong&gt;, ensuring that DynamoDB knows how to store and index it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;"123"&lt;/code&gt; is the &lt;strong&gt;value&lt;/strong&gt; assigned to the &lt;code&gt;UserID&lt;/code&gt; attribute.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While DynamoDB is NoSQL, it still enforces strict data types and naming rules to ensure consistency. These are detailed in the &lt;a href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.NamingRulesDataTypes.html" rel="noopener noreferrer"&gt;DynamoDB Developer Guide&lt;/a&gt;, but here's a quick rundown of supported data types as of March 2025:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;S&lt;/code&gt;&lt;/strong&gt; – String&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;N&lt;/code&gt;&lt;/strong&gt; – Number&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;B&lt;/code&gt;&lt;/strong&gt; – Binary&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;BOOL&lt;/code&gt;&lt;/strong&gt; – Boolean&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;NULL&lt;/code&gt;&lt;/strong&gt; – Null&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;M&lt;/code&gt;&lt;/strong&gt; – Map&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;L&lt;/code&gt;&lt;/strong&gt; – List&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;SS&lt;/code&gt;&lt;/strong&gt; – String Set&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;NS&lt;/code&gt;&lt;/strong&gt; – Number Set&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;BS&lt;/code&gt;&lt;/strong&gt; – Binary Set&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Step Functions Config
&lt;/h4&gt;

&lt;p&gt;So how do I apply this to Step Functions? Well, remember when I set variables in the output of the Lambda function? Step Functions lets me reference those variables here.&lt;/p&gt;

&lt;p&gt;Here's how I store a &lt;code&gt;make&lt;/code&gt; attribute in DynamoDB, using my &lt;code&gt;$make&lt;/code&gt; variable in a JSONata expression:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "TableName": "REDACTED",
    "Item": {
        "make": { "S": "{% $make %}" }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is equivalent to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "TableName": "REDACTED",
    "Item": {
        "make": { "S": "FORD" }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using JSONata, I can dynamically inject values during execution instead of hardcoding them.&lt;/p&gt;

&lt;p&gt;Now let's add a &lt;code&gt;yearOfManufacture&lt;/code&gt; attribute:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "TableName": "REDACTED",
    "Item": {
        "make": { "S": "{% $make %}" },
        "yearOfManufacture": { "N": "{% $yearOfManufacture %}" }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This pattern continues for my other attributes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "TableName": "REDACTED",
  "Item": {
    "make": {
      "S": "{% $make %}"
    },
    "yearOfManufacture": {
      "N": "{% $yearOfManufacture%}"
    },
    "engineCapacity": {
      "N": "{% $engineCapacity %}"
    },
    "co2Emissions": {
      "N": "{% $co2Emissions%}"
    },
    "fuelType": {
      "S": "{% $fuelType %}"
    },
    "markedForExport": {
      "BOOL": "{% $markedForExport %}"
    },
    "colour": {
      "S": "{% $colour %}"
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All this is then passed as an Argument to the &lt;code&gt;DynamoDB: PutItem&lt;/code&gt; action in the state machine's ASL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    "DynamoDB PutItem": {
      "Type": "Task",
      "Resource": "arn:aws:states:::dynamodb:putItem",
      "Arguments": {
        "TableName": "REDACTED",
        "Item": {
          "make": {
            "S": "{% $make %}"
          },
          "yearOfManufacture": {
            "N": "{% $yearOfManufacture%}"
          },
          "engineCapacity": {
            "N": "{% $engineCapacity %}"
          },
          "co2Emissions": {
            "N": "{% $co2Emissions%}"
          },
          "fuelType": {
            "S": "{% $fuelType %}"
          },
          "markedForExport": {
            "BOOL": "{% $markedForExport %}"
          },
          "colour": {
            "S": "{% $colour %}"
          }
        }
      }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, &lt;code&gt;DynamoDB:PutAction&lt;/code&gt; gets the same error handling as &lt;code&gt;Lambda:Invoke&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So I got all this working first time, right? Well...&lt;/p&gt;

&lt;h4&gt;
  
  
  DynamoDB Issues
&lt;/h4&gt;

&lt;p&gt;During my first attempts, I got this error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;An error occurred while executing the state 'DynamoDB PutItem'.

The Parameters '{"TableName":"REDACTED","Item":{"make":{"S":"FORD"},"yearOfManufacture":{"N":2014}}}' could not be used to start the Task:

[The value for the field 'N' must be a STRING]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ok. Not the first time I've seen data type problems. I'll just change the &lt;code&gt;yearOfManufacture&lt;/code&gt; data type to &lt;code&gt;"S"(string)&lt;/code&gt; and try again...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;An error occurred while executing the state 'DynamoDB PutItem'.

The Parameters '{"TableName":"REDACTED","Item":{"make":{"S":"FORD"},"yearOfManufacture":{"S":2014}}}' could not be used to start the Task:

[The value for the field 'S' must be a STRING]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;DynamoDB rejected both approaches (╯°□°)╯︵ ┻━┻&lt;/p&gt;

&lt;p&gt;The issue wasn't the data type, but how it was formatted. DynamoDB treats numbers as &lt;strong&gt;strings&lt;/strong&gt; in its JSON-like structure, so even when using numbers they must be wrapped in &lt;strong&gt;quotes&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In the case of &lt;code&gt;yearOfManufacture&lt;/code&gt;, where I was providing &lt;code&gt;2014&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"yearOfManufacture": {"N": 2014}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;DynamoDB needed &lt;code&gt;"2014"&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"yearOfManufacture": {"N": "2014"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thankfully, JSONata came to the rescue again! Remember &lt;a href="https://docs.jsonata.org/string-functions#string" rel="noopener noreferrer"&gt;the &lt;code&gt;$string&lt;/code&gt; function&lt;/a&gt; from the Lambda section? Well, &lt;code&gt;$string&lt;/code&gt; casts the given argument to a string!&lt;/p&gt;

&lt;p&gt;So this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"yearOfManufacture": "{% $states.result.Payload.body.yearOfManufacture %}"

&amp;gt; 2014
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Becomes this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"yearOfManufacture": "{% $string($states.result.Payload.body.yearOfManufacture) %}"

&amp;gt; "2014"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This solved the problem with no Lambda function changes or additional states!&lt;/p&gt;

&lt;h3&gt;
  
  
  Amazon SNS
&lt;/h3&gt;

&lt;p&gt;After successfully writing data to DynamoDB, I want to include a confirmation step by sending a notification through Amazon SNS.&lt;/p&gt;

&lt;p&gt;While this approach is not recommended for high-volume use cases because of potential costs and notification fatigue, it can be helpful for testing, monitoring, and debugging. Additionally, it offers an opportunity to reuse variables from previous states and dynamically format a message using JSONata.&lt;/p&gt;

&lt;p&gt;The goal is to send an email notification like this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A 2014 GREY FORD has been added to DynamoDB on (&lt;em&gt;current date and time&lt;/em&gt;)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To do this, I'll use:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;$yearOfManufacture&lt;/code&gt; for the vehicle's year (2014)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;$colour&lt;/code&gt; for the vehicle's colour (GREY)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;$make&lt;/code&gt; for the manufacturer (FORD)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Plus the &lt;a href="https://docs.jsonata.org/date-time-functions#now" rel="noopener noreferrer"&gt;JSONata &lt;code&gt;$now()&lt;/code&gt; function&lt;/a&gt; for the current date and time. This generates a UTC timestamp in &lt;a href="https://en.wikipedia.org/wiki/ISO_8601" rel="noopener noreferrer"&gt;ISO 8601-compatible&lt;/a&gt; format and returns it as a string. E.g. &lt;code&gt;"2025-02-25T19:12:59.152Z"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;So the code will look something like:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A &lt;code&gt;$yearOfManufacture&lt;/code&gt; &lt;code&gt;$colour&lt;/code&gt; &lt;code&gt;$make&lt;/code&gt; has been added to DynamoDB on &lt;code&gt;$now()&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Which translates to this JSONata expression:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{% 'A ' &amp;amp; $yearOfManufacture &amp;amp; ' ' &amp;amp; $colour &amp;amp; ' ' &amp;amp; $make &amp;amp; ' has been added to DynamoDB on ' &amp;amp; $now() %}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's analyse each part of the JSONata expression to understand how it builds the final message:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{%

  'A '
&amp;amp; 
  $yearOfManufacture 
&amp;amp; 
  ' ' 
&amp;amp; 
  $colour 
&amp;amp; 
  ' ' 
&amp;amp; 
  $make 
&amp;amp; 
  ' has been added to DynamoDB on ' 
&amp;amp; 
  $now() 

%}"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each part of this expression plays a specific role:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;'A '&lt;/strong&gt; | &lt;strong&gt;' has been added to DynamoDB on '&lt;/strong&gt;: Static strings &amp;amp; spaces.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;$yearOfManufacture&lt;/code&gt; | &lt;code&gt;$colour&lt;/code&gt; | &lt;code&gt;$make&lt;/code&gt;: Dynamic values.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;$now()&lt;/code&gt;: JSONata function.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;' '&lt;/strong&gt;: Static spaces to separate JSONata variable outputs.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The static spaces are important! Without them, I'd get this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;2014GREYFORD&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Instead of the expected:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;2014 GREY FORD&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This JSONata expression is passed as the &lt;code&gt;Message&lt;/code&gt; argument in the &lt;code&gt;SNS:Publish&lt;/code&gt; action, ensuring the notification contains the correctly formatted message:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Message": "{% 'A ' &amp;amp; $yearOfManufacture &amp;amp; ' ' &amp;amp; $colour &amp;amp; ' ' &amp;amp; $make &amp;amp; ' has been added to DynamoDB on ' &amp;amp; $now() %}"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, to integrate this with Step Functions it is included in the &lt;code&gt;SNS Publish: Success&lt;/code&gt; task ASL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"SNS Publish: Success": {
    "Type": "Task",
    "Resource": "arn:aws:states:::sns:publish",
    "Arguments": {
      "Message": "{% 'A ' &amp;amp; $yearOfManufacture &amp;amp; ' ' &amp;amp; $colour &amp;amp; ' ' &amp;amp; $make &amp;amp; ' has been added to DynamoDB on ' &amp;amp; $now() %}",
      "TopicArn": "arn:aws:sns:REDACTED:success-stepfunction"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Final Workflow
&lt;/h3&gt;

&lt;p&gt;Finally, let's see what the workflows look like. Here's the workflow graph:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2kci4cedjll2mzy3lnue.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2kci4cedjll2mzy3lnue.png" alt="stepfunctions graph"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And here's &lt;a href="https://github.com/MrDamienJones/amazonwebshark-Artefacts/blob/master/2025/2025-03-03-SimplifiedDataWorkflowsWithAWSStepFunctionsVariables/simplifiedstepfunctionvariablesworkflow.yaml" rel="noopener noreferrer"&gt;the workflow ASL on GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing
&lt;/h2&gt;

&lt;p&gt;In this section, I run some test executions against my simplified Step Functions workflow and check the variables. I'll test four requests - two valid and two invalid.&lt;/p&gt;

&lt;h3&gt;
  
  
  Valid Request: Ford
&lt;/h3&gt;

&lt;p&gt;Firstly, what happens when a valid API request is made and everything works as expected?&lt;/p&gt;

&lt;p&gt;The Step Functions execution succeeds:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwcfa05382ym78dacmmo7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwcfa05382ym78dacmmo7.png" alt="stepfunctions graph testsuccess"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each state completes successfully:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqvxos0pq8s8t6gs69zen.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqvxos0pq8s8t6gs69zen.png" alt="2025 02 26 StateViewSuccess"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;My DynamoDB table now contains one item:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu4xhozd1xk0y4equysl3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu4xhozd1xk0y4equysl3.png" alt="2025 02 26 DyDBTable1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I receive a confirmation email from SNS:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxsf8uh1gd5zbxcvr4nb0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxsf8uh1gd5zbxcvr4nb0.png" alt="2025 02 26 SNSSuccessFord"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If I send the same request again, the existing DynamoDB item is overwritten because the primary key remains the same.&lt;/p&gt;

&lt;h3&gt;
  
  
  Valid Request: Audi
&lt;/h3&gt;

&lt;p&gt;Next, what happens if I make a valid request for a &lt;strong&gt;different&lt;/strong&gt; car? The steps repeat as above, and my DynamoDB table now has two items:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fflz0d3wxfbmntxmxwgpn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fflz0d3wxfbmntxmxwgpn.png" alt="2025 02 26 DyDBTable2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And I get a different email:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4cm9g9devz1ebx8tc5b9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4cm9g9devz1ebx8tc5b9.png" alt="2025 02 26 SNSSuccessAudi"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Invalid Request
&lt;/h3&gt;

&lt;p&gt;Next, what happens if the car in my request doesn't exist? Well, it does fail, but in an unexpected way:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8h0eyqh32g3fo8j73ax0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8h0eyqh32g3fo8j73ax0.png" alt="stepfunctions graphfail"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The API returns an error response:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Payload": {
      "statusCode": 500,
      "body": "{\"error\": \"API request failed: 400 Client Error: Bad Request for url"}"
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I'd expected the response to be passed to the &lt;code&gt;Choice&lt;/code&gt; state, which would then notice the &lt;code&gt;500&lt;/code&gt; status code and start the Fail process. But this happened instead:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzvdco10wwtmgqol4x22i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzvdco10wwtmgqol4x22i.png" alt="2025 02 26 StateViewFail"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The failure occurs at the assignment of the Lambda action variable! It attempts to assign a &lt;code&gt;yearOfManufacture&lt;/code&gt; value from the API response body to a variable, but since there is no response body the assignment fails:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "cause": "An error occurred while executing the state 'Lambda Invoke' (entered at the event id #2). The JSONata expression '$states.result.Payload.body.yearOfManufacture ' specified for the field 'Assign/yearOfManufacture ' returned nothing (undefined).",
  "error": "States.QueryEvaluationError",
  "location": "Assign/registrationNumber",
  "state": "Lambda Invoke"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I also get an email, but this one is less fancy as it just dumps the whole output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4vnw39daqltmqa1s9jjn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4vnw39daqltmqa1s9jjn.png" alt="2025 02 26 SNSFail"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So I still get my Fail outcome - just not in the expected way. Despite this, the &lt;code&gt;Choice&lt;/code&gt; state remains valuable for preventing invalid data from entering DynamoDB.&lt;/p&gt;

&lt;h3&gt;
  
  
  No Request
&lt;/h3&gt;

&lt;p&gt;Finally, what happens if no data is passed to the state machine at all?&lt;/p&gt;

&lt;p&gt;Actually, this situation is very similar to the invalid request! There's a different error message in the log:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Payload": {
      "statusCode": 400,
      "body": "{\"error\": \"Registration number not provided\"}"
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But otherwise it's the same events and outcome. The Lambda variable assignment fails, triggering an SNS email and an &lt;code&gt;ExecutionFailed&lt;/code&gt; result.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cost Analysis
&lt;/h2&gt;

&lt;p&gt;This section examines the costs of my simplified Step Functions variables workflow. This section is brief since all services used in this workflow fall within the AWS Free Tier! For transparency, I'll include my billing metrics for the month. These are account-wide, and I'm still nowhere near paying AWS anything!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DynamoDB:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;$0.1415 per million read request units (EU (Ireland))&lt;/td&gt;
&lt;td&gt;30.5 ReadRequestUnits&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;$0.705 per million write request units (EU (Ireland))&lt;/td&gt;
&lt;td&gt;13 WriteRequestUnits&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Lambda:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;AWS Lambda - Compute Free Tier - 400,000 GB-Seconds - EU (Ireland)&lt;/td&gt;
&lt;td&gt;76.219 Second&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;AWS Lambda - Requests Free Tier - 1,000,000 Requests - EU (Ireland)&lt;/td&gt;
&lt;td&gt;110 Request&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;SNS:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;First 1,000 Amazon SNS Email/Email-JSON Notifications per month are free&lt;/td&gt;
&lt;td&gt;19 Notifications&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;First 1,000,000 Amazon SNS API Requests per month are free&lt;/td&gt;
&lt;td&gt;289 Requests&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step Functions:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;
&lt;td&gt;$0 for first 4,000 state transitions&lt;/td&gt;
&lt;td&gt;431 StateTransitions&lt;/td&gt;
&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This experiment demonstrates how cost-effective Step Functions can be. As long as my usage remains within the Free Tier, I pay nothing! If my workflow grows, I’ll monitor costs and optimise accordingly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;In this post, I used AWS Step Functions variables and JSONata to create a simplified API data capture workflow with Lambda and DynamoDB.&lt;/p&gt;

&lt;p&gt;With a background in SQL and Python, I'm no stranger to variables, and I love that they're now a native part of Step Functions. AWS keeps enhancing Step Functions every few months, making it more powerful and versatile. The introduction of variables unlocks new possibilities for data manipulation, serverless applications and event-driven workflows, and I'm excited to explore them further in the coming months!&lt;/p&gt;

&lt;p&gt;For a visual walkthrough of Step Functions variables and JSONata, check out this &lt;a href="https://www.youtube.com/playlist?list=PLJo-rJlep0EBdcNkQM7xBkpahnrtk7qbe" rel="noopener noreferrer"&gt;Serverless Office Hours&lt;/a&gt; episode with AWS Principal Developer Advocates &lt;a href="https://www.linkedin.com/in/singledigit/" rel="noopener noreferrer"&gt;Eric Johnson&lt;/a&gt; and &lt;a href="https://www.linkedin.com/in/julianrwood/" rel="noopener noreferrer"&gt;Julian Wood&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/MKGjsFHtX30"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;If this post has been useful then the button below has links for contact, socials, projects and sessions:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://gravatar.com/damienjonesshark" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2dv1t3pwsh6f46n9sd5e.png" alt="SharkLinkButton 1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks for reading &lt;del&gt;^&lt;/del&gt;&lt;/p&gt;

</description>
      <category>amazondynamodb</category>
      <category>awslambda</category>
      <category>awsstepfunctions</category>
      <category>jsonata</category>
    </item>
    <item>
      <title>Low-Code S3 Key Validation With AWS Step Functions &amp; JSONata</title>
      <dc:creator>Damien Jones</dc:creator>
      <pubDate>Thu, 01 May 2025 10:37:47 +0000</pubDate>
      <link>https://dev.to/aws-builders/low-code-s3-key-validation-with-aws-step-functions-jsonata-1m8f</link>
      <guid>https://dev.to/aws-builders/low-code-s3-key-validation-with-aws-step-functions-jsonata-1m8f</guid>
      <description>&lt;p&gt;In this post, I use &lt;a href="https://jsonata.org/" rel="noopener noreferrer"&gt;JSONata&lt;/a&gt; to add low-code S3 object key validation to an AWS Step Functions state machine.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This post was originally published on &lt;a href="https://amazonwebshark.com/low-code-s3-key-validation-with-aws-step-functions-jsonata/" rel="noopener noreferrer"&gt;amazonwebshark.com&lt;/a&gt; on 17 February 2025. Some of the formatting and snippets are best viewed there, although the wording is identical. - Damien&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In 2024, I worked a lot with AWS Step Functions. I built several for different tasks, &lt;a href="https://amazonwebshark.com/projects/#wordpress-aws-data-pipeline-2024" rel="noopener noreferrer"&gt;wrote multiple blog posts about them&lt;/a&gt; and &lt;a href="https://amazonwebshark.com/speaking/#2024" rel="noopener noreferrer"&gt;talked about them a fair bit&lt;/a&gt;. So when AWS introduced JSONata support for Step Functions last year, I was very interested. Although I had no prior JSONata experience, I heard positive feedback and made a mental note to explore its use cases.&lt;/p&gt;

&lt;p&gt;Well, there's no time like the present! And as I was starting to create the first &lt;a href="https://amazonwebshark.com/project-wolfie-honouring-an-absent-friend-with-music/" rel="noopener noreferrer"&gt;Project Wolfie&lt;/a&gt; resources I realised some of my requirements were a perfect fit.&lt;/p&gt;

&lt;p&gt;Firstly, I will examine what JSONata is, how it works and why it's useful. Next, I will outline my architecture and create some low-code S3 key validation JSONata expressions. Finally, I'll test these expressions and review their outputs.&lt;/p&gt;

&lt;h2&gt;
  
  
  JSONata &amp;amp; AWS
&lt;/h2&gt;

&lt;p&gt;This section introduces JSONata and examines its syntax and benefits.&lt;/p&gt;

&lt;h3&gt;
  
  
  Introducing JSONata
&lt;/h3&gt;

&lt;p&gt;JSONata is a lightweight query and transformation language for JSON, developed by &lt;a href="https://www.linkedin.com/in/andrew-coleman-6166245a/" rel="noopener noreferrer"&gt;Andrew Coleman&lt;/a&gt; in 2016. Specifically inspired by &lt;a href="https://en.wikipedia.org/wiki/XPath" rel="noopener noreferrer"&gt;XPath&lt;/a&gt; and SQL, it enables sophisticated queries using a compact and intuitive notation.&lt;/p&gt;

&lt;p&gt;JSONata provides built-in operators and functions for efficiently extracting and transforming data into any JSON structure. It also supports user-defined functions, allowing for advanced expressions that enhance the querying of dynamic JSON data.&lt;/p&gt;

&lt;p&gt;For a visual introduction, check out this JSONata overview:&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/ZBaK40rtIBM"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  JSONata Syntax Essentials
&lt;/h3&gt;

&lt;p&gt;JSONata has a simple and expressive syntax. Its path-based approach lets developers easily navigate nested structures. It combines functional programming with dot notation for navigation, brackets for filtering and pipeline operators for chaining.&lt;/p&gt;

&lt;p&gt;JSONata operations include transformations like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Arithmetic (&lt;code&gt;$price * 1.2&lt;/code&gt;)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Conditional Logic (&lt;code&gt;$price &amp;gt; 100 ? 'expensive' : 'affordable'&lt;/code&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Filtering (&lt;code&gt;$orders[status = 'shipped']&lt;/code&gt;)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;String Operations (&lt;code&gt;$firstName &amp;amp; ' ' &amp;amp; $lastName&lt;/code&gt;)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The JSONata site includes &lt;a href="https://docs.jsonata.org/overview.html" rel="noopener noreferrer"&gt;full documentation&lt;/a&gt; and a &lt;a href="https://try.jsonata.org/" rel="noopener noreferrer"&gt;JSONata Exerciser&lt;/a&gt; for experimenting.&lt;/p&gt;

&lt;h3&gt;
  
  
  JSONata In AWS Step Functions
&lt;/h3&gt;

&lt;p&gt;JSONata was introduced to &lt;a href="https://aws.amazon.com/blogs/compute/simplifying-developer-experience-with-variables-and-jsonata-in-aws-step-functions/" rel="noopener noreferrer"&gt;AWS Step Functions in November 2024&lt;/a&gt;. Using JSONata in Step Functions requires setting the &lt;code&gt;QueryLanguage&lt;/code&gt; field to &lt;code&gt;JSONata&lt;/code&gt; in the state machine definition. This action replaces the traditional JSONPath fields with two JSONata fields:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Arguments&lt;/code&gt;: Used to customise data sent to state actions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Output&lt;/code&gt;: Used to transform results into custom state output.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Additionally, the &lt;code&gt;Assign&lt;/code&gt; field sets variables that can be stored and reused across the workflow.&lt;/p&gt;

&lt;p&gt;In AWS Step Functions, JSONata expressions are enclosed in &lt;code&gt;{% %}&lt;/code&gt; delimiters but otherwise follow standard JSONata syntax. They access data using the &lt;code&gt;$states&lt;/code&gt; reserved variable with the following structures:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;State input is accessed using &lt;code&gt;$states.input&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Context information is accessed using &lt;code&gt;$states.context&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Task results (if successful) are accessed using &lt;code&gt;$states.result&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Error outputs (if existing) are accessed using &lt;code&gt;$states.errorOutput&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Step Functions includes standard JSONata functions as well as AWS-specific additions like &lt;code&gt;$partition&lt;/code&gt;, &lt;code&gt;$range&lt;/code&gt;, &lt;code&gt;$hash&lt;/code&gt;, &lt;code&gt;$random&lt;/code&gt;, and &lt;code&gt;$uuid&lt;/code&gt;. Some functions, such as &lt;code&gt;$eval&lt;/code&gt;, are &lt;strong&gt;not&lt;/strong&gt; supported.&lt;/p&gt;

&lt;p&gt;Here are some JSONata examples from the &lt;a href="https://docs.aws.amazon.com/step-functions/latest/dg/transforming-data.html" rel="noopener noreferrer"&gt;AWS Step Functions Developer Guide&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{% $states.input.title %}

{% $current_price &amp;lt;= $states.input.desired_priced %}

{% $parse($states.input.json_string) %}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Talking more about this subject is AWS Principle Developer Advocate &lt;a href="https://www.linkedin.com/in/singledigit/" rel="noopener noreferrer"&gt;Eric Johnson&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/kVWxJoO_zc8"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  JSONata Benefits
&lt;/h3&gt;

&lt;p&gt;So why is JSONata in AWS a big deal?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Low Maintenance&lt;/strong&gt;: JSONata use removes the need for Lambda runtime updates, dependency management and security patching. JSONata expressions are self-contained and version-free, reducing debugging and testing effort.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Simpler Development Workflow&lt;/strong&gt;: JSONata's standardised syntax removes decisions about languages, runtimes and tooling. This improves consistency, simplifies collaboration and speeds up development.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Releases Capacity&lt;/strong&gt;: JSONata use reduces reliance on AWS Lambda, freeing up Lambda concurrency slots for more complex tasks. This minimises throttling risks and can lower Lambda costs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Faster Execution&lt;/strong&gt;: JSONata runs inside AWS services, avoiding cold starts, IAM role checks and network latency. Most JSONata transformations are complete in milliseconds, making it ideal for high-throughput APIs and real-time systems.&lt;/p&gt;

&lt;h2&gt;
  
  
  Architecture
&lt;/h2&gt;

&lt;p&gt;This section explains the key features and events used in my low-code S3 validation architecture with JSONata.&lt;/p&gt;

&lt;h3&gt;
  
  
  Object Created Event
&lt;/h3&gt;

&lt;p&gt;My process starts when an S3 object is created. For this post, I'm using &lt;a href="https://aws.amazon.com/eventbridge/" rel="noopener noreferrer"&gt;Amazon EventBridge&lt;/a&gt;'s sample S3 Object Created event:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "version": "0",
  "id": "17793124-05d4-b198-2fde-7ededc63b103",
  "detail-type": "Object Created",
  "source": "aws.s3",
  "account": "123456789012",
  "time": "2021-11-12T00:00:00Z",
  "region": "ca-central-1",
  "resources": ["arn:aws:s3:::example-bucket"],
  "detail": {
    "version": "0",
    "bucket": {
      "name": "example-bucket"
    },
    "object": {
      "key": "example-key",
      "size": 5,
      "etag": "b1946ac92492d2347c6235b4d2611184",
      "version-id": "IYV3p45BT0ac8hjHg1houSdS1a.Mro8e",
      "sequencer": "00617F08299329D189"
    },
    "request-id": "N4N7GDK58NMKJ12R",
    "requester": "123456789012",
    "source-ip-address": "1.2.3.4",
    "reason": "PutObject"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the highlighted &lt;strong&gt;key&lt;/strong&gt; field is vital as it identifies the uploaded object. This field will be used in the validation processes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Choice State
&lt;/h3&gt;

&lt;p&gt;In AWS Step Functions, &lt;a href="https://docs.aws.amazon.com/step-functions/latest/dg/state-choice.html" rel="noopener noreferrer"&gt;&lt;code&gt;Choice&lt;/code&gt; states&lt;/a&gt; introduce conditional logic to a state machine. They assess conditions and guide execution accordingly, allowing workflows to branch dynamically based on input data. When used with JSONata, a &lt;code&gt;Choice&lt;/code&gt; state must contain the following fields:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;Condition&lt;/code&gt; field&lt;/strong&gt; – a JSONata expression that evaluates to &lt;code&gt;true&lt;/code&gt;/&lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;Next&lt;/code&gt; field&lt;/strong&gt; – a value that must match a state name in the state machine.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, this &lt;code&gt;Choice&lt;/code&gt; state checks if a variable &lt;code&gt;foo&lt;/code&gt; equals &lt;code&gt;1&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{"Condition": "{% $foo = 1 %}",  "Next": "NumericMatchState"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If &lt;code&gt;$foo = 1&lt;/code&gt;, the condition is &lt;code&gt;true&lt;/code&gt; and the workflow transitions to a &lt;code&gt;NumericMatchState&lt;/code&gt; state.&lt;/p&gt;

&lt;h3&gt;
  
  
  Architecture Diagram
&lt;/h3&gt;

&lt;p&gt;Now let's put this all together into an architecture diagram:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd0pwdzv21djkzbubrye5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd0pwdzv21djkzbubrye5.png" alt="Architecture "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;A file is uploaded to an Amazon S3 Bucket.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;S3 creates an &lt;a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/notification-content-structure.html" rel="noopener noreferrer"&gt;Object Created event&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Amazon EventBridge matches the event record to an event rule.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Eventbridge executes the AWS Step Functions state machine and passes the event to it as JSON input.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The state machine transitions through the various choice states.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The state machine transitions to the fail state if &lt;strong&gt;any&lt;/strong&gt; choice state criteria are &lt;strong&gt;not&lt;/strong&gt; met.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The state machine transitions to the success state if &lt;strong&gt;all&lt;/strong&gt; choice state criteria &lt;strong&gt;are&lt;/strong&gt; met.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Expression Creation
&lt;/h2&gt;

&lt;p&gt;In this section, I create JSONata expressions to perform low-code S3 validation. For clarity, I'll use this sample S3 event including an object key which closely resembles my actual S3 path:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "version": "0",
  ...
  "detail": {
    "version": "0",
    "bucket": {
      "name": "data-lakehouse-raw"
    },
    "object": {
      "key": "iTunes/iTunes-AllTunes-2025-02-01.txt",
      "size": 5,
      ...
    },
    "request-id": "N4N7GDK58NMKJ12R",
    "requester": "123456789012",
    "source-ip-address": "1.2.3.4",
    "reason": "PutObject"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  S3 Key TXT Suffix Check
&lt;/h3&gt;

&lt;p&gt;This JSONata expression checks if the S3 object key ends with &lt;code&gt;txt&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{% $lowercase($split($split($states.input.detail.object.key, '/')[-1], '.')[-1]) = 'txt' %}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For better readability:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{% 
  $lowercase(
    $split(
      $split($states.input.detail.object.key, '/')[-1], 
    '.')[-1]
  ) = 'txt' 
%}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's walk through this step by step:&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;1. Accessing The S3 Object Key&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Extract the key from the event using &lt;code&gt;$states.input&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$states.input.detail.object.key
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;➡ &lt;strong&gt;Output:&lt;/strong&gt; &lt;code&gt;"iTunes/iTunes-AllTunes-2025-02-01.txt"&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;2. Splitting By &lt;code&gt;/&lt;/code&gt; To Extract The Filename&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Break the key into an array with &lt;code&gt;[%split](https://docs.jsonata.org/string-functions#split)&lt;/code&gt; using &lt;code&gt;/&lt;/code&gt; as the delimiter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$split($states.input.detail.object.key, '/')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;➡ &lt;strong&gt;Output:&lt;/strong&gt; &lt;code&gt;["iTunes", "iTunes-AllTunes-2025-02-01.txt"]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now, retrieve the array's last element (the object name) using &lt;code&gt;[-1]&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$split(...)[-1]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;➡ &lt;strong&gt;Output:&lt;/strong&gt; &lt;code&gt;"iTunes-AllTunes-2025-02-01.txt"&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;3. Splitting By &lt;code&gt;.&lt;/code&gt; To Extract The File Suffix&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Break the filename with &lt;code&gt;$split&lt;/code&gt; again, using &lt;code&gt;.&lt;/code&gt; as the delimiter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$split($split(...)[-1], '.')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;➡ &lt;strong&gt;Output:&lt;/strong&gt; &lt;code&gt;["iTunes-AllTunes-2025-02-01", "txt"]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now, retrieve the last element (the suffix) using &lt;code&gt;[-1]&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$split($split(...)[-1], '.')[-1]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;➡ &lt;strong&gt;Output:&lt;/strong&gt; &lt;code&gt;"txt"&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;4. Converting To Lowercase For Case-Insensitive Matching&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Use &lt;code&gt;[$lowercase](https://docs.jsonata.org/string-functions#lowercase)&lt;/code&gt; to convert the suffix to lowercase:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$lowercase($split(...)[-1], '.')[-1])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;➡ &lt;strong&gt;Output:&lt;/strong&gt; &lt;code&gt;"txt"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;$lowercase&lt;/code&gt; function ensures consistency, as files with &lt;strong&gt;TXT, Txt, or tXt&lt;/strong&gt; extensions will still match correctly. Here, there is no change as &lt;code&gt;txt&lt;/code&gt; is already lowercase.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;5. Comparing Against&lt;/strong&gt; &lt;code&gt;'**txt**'&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;Finally, compare the result to &lt;code&gt;'txt'&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$lowercase($split(...)[-1], '.')[-1]) = 'txt'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;➡ &lt;strong&gt;Output:&lt;/strong&gt; &lt;code&gt;true&lt;/code&gt; ✅&lt;/p&gt;

&lt;p&gt;This means that files ending in &lt;strong&gt;.txt&lt;/strong&gt; pass validation, while others fail.&lt;/p&gt;

&lt;h3&gt;
  
  
  S3 Key iTunes String Check
&lt;/h3&gt;

&lt;p&gt;This JSONata expression checks if the S3 object key contains &lt;code&gt;iTunes&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{% $contains($split($states.input.detail.object.key, '/')[-1], 'iTunes') %}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For better readability:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{% 
  $contains(
    $split(
      $states.input.detail.object.key, '/')[-1],
    'iTunes'
  ) 
%}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I'm not using &lt;code&gt;$lowercase&lt;/code&gt; this time, as &lt;code&gt;iTunes&lt;/code&gt; is the correct spelling.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;1. Extract The Filename&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;This is unchanged from the last expression:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$split($states.input.detail.object.key, '/')[-1]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;➡ &lt;strong&gt;Output:&lt;/strong&gt; &lt;code&gt;"iTunes-AllTunes-2025-02-01.txt"&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;2. Check If The String Contains&lt;/strong&gt; &lt;code&gt;**'iTunes**'&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;[$contains](https://docs.jsonata.org/string-functions#contains)&lt;/code&gt; function checks if the string contains the specified substring. It returns &lt;code&gt;true&lt;/code&gt; if the substring exists; otherwise, it returns &lt;code&gt;false&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$contains($split(...)[-1], 'iTunes')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;➡ &lt;strong&gt;Output:&lt;/strong&gt; &lt;code&gt;true&lt;/code&gt; ✅ if &lt;code&gt;'iTunes'&lt;/code&gt; appears anywhere in the filename.&lt;/p&gt;

&lt;p&gt;So:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;✅ &lt;code&gt;"iTunes-AllTunes-2025-02-01.txt"&lt;/code&gt; → &lt;code&gt;true&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;❌ &lt;code&gt;"itunes-AllTunes-2025-02-01.txt"&lt;/code&gt; → &lt;code&gt;false&lt;/code&gt; (case-sensitive)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  S3 Key Date Check
&lt;/h3&gt;

&lt;p&gt;This JSONata expression checks if the S3 object key contains a date with format &lt;code&gt;YYYY-MM-DD&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{% $exists($match($split($states.input.detail.object.key, '/')[-1], /\d{4}-\d{2}-\d{2}/)) %}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For better readability:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$exists(
  $match(
    $split($states.input.detail.object.key, '/')[-1], 
    /\d{4}-\d{2}-\d{2}/
  )
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;strong&gt;1. Extract The Filename&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;This is unchanged from the first expression:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$split($states.input.detail.object.key, '/')[-1]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;➡ &lt;strong&gt;Output:&lt;/strong&gt; &lt;code&gt;"iTunes-AllTunes-2025-02-01.txt"&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;2. Apply The Regex Match&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;[$match](https://docs.jsonata.org/string-functions#match)&lt;/code&gt; function applies the substring to the provided regular expression (regex). If found, an array of objects is returned containing the following fields:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;match&lt;/code&gt; - the substring that was matched by the regex.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;index&lt;/code&gt; - the offset (starting at zero) within the substring.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;groups&lt;/code&gt; - if the regex contains capturing groups (parentheses), this contains an array of strings representing each captured group.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this JSONata expression:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$match(..., /\d{4}-\d{2}-\d{2}/)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The regex looks for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;\d{4}&lt;/code&gt;&lt;/strong&gt; → Four digits (year)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;-&lt;/code&gt;&lt;/strong&gt; → Hyphen separator&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;\d{2}&lt;/code&gt;&lt;/strong&gt; → Two digits (month)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;-&lt;/code&gt;&lt;/strong&gt; → Another hyphen&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;\d{2}&lt;/code&gt;&lt;/strong&gt; → Two digits (day)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;➡ &lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "match": "2025-02-01",
  "index": 16,
  "groups": []
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;strong&gt;3. Convert To Boolean With &lt;code&gt;$exists&lt;/code&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;I can't use the &lt;code&gt;$match&lt;/code&gt; output yet as the &lt;code&gt;Choice&lt;/code&gt; state needs a boolean output. Enter &lt;code&gt;[$exists](https://docs.jsonata.org/boolean-functions#exists)&lt;/code&gt;. This function returns &lt;code&gt;true&lt;/code&gt; for a successful match; otherwise, it returns &lt;code&gt;false&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$exists($match(..., /\d{4}-\d{2}-\d{2}/))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;➡ &lt;strong&gt;Output:&lt;/strong&gt; &lt;code&gt;true&lt;/code&gt; ✅ if a date is found.&lt;/p&gt;

&lt;p&gt;Here, &lt;code&gt;$exists&lt;/code&gt; returns &lt;code&gt;true&lt;/code&gt; as a date is present. However, note that JSONata lacks built-in functions to &lt;strong&gt;validate&lt;/strong&gt; dates. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;"2025-02-01"&lt;/code&gt; → &lt;code&gt;true&lt;/code&gt; (valid date)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;"2025-02-31"&lt;/code&gt; → &lt;code&gt;true&lt;/code&gt; (invalid date but still matches format)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;An AWS Lambda function would be needed for strict date validation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Combining JSONata Expressions
&lt;/h3&gt;

&lt;p&gt;Although I've created separate &lt;code&gt;Choice&lt;/code&gt; states for each JSONata expression in this section, I will add that all the expressions can be combined into a single &lt;code&gt;Choice&lt;/code&gt; state using &lt;code&gt;[and](https://docs.jsonata.org/expressions#boolean-expressions)&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{% $lowercase($split($split($states.input.detail.object.key, '/')[-1], '.')[-1]) = 'txt' and $contains($split($states.input.detail.object.key, '/')[-1], 'iTunes') and $exists($match($split($states.input.detail.object.key, '/')[-1], /\\d{4}-\\d{2}-\\d{2}/)) %}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For better readability:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{% 
  $lowercase(
    $split(
      $split(
        $states.input.detail.object.key, '/')[-1], '.')[-1]) = 'txt' 
and 
  $contains(
    $split(
      $states.input.detail.object.key, '/')[-1], 'iTunes') 
and 
  $exists(
    $match(
      $split(
        $states.input.detail.object.key, '/')[-1], /\\d{4}-\\d{2}-\\d{2}/)) 
%}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When deciding whether to do this, consider these &lt;strong&gt;benefits&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Simplified Structure&lt;/strong&gt;: Reducing the number of states can make the state machine easier to understand and maintain visually. Instead of multiple branching paths, all logic is in one centralised &lt;code&gt;Choice&lt;/code&gt; state.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cost Optimisation&lt;/strong&gt;: &lt;a href="https://aws.amazon.com/step-functions/pricing/" rel="noopener noreferrer"&gt;AWS Step Functions Standard Workflows pricing&lt;/a&gt; is based on the number of state transitions. Combining multiple &lt;code&gt;Choice&lt;/code&gt; states into one reduces transitions, potentially lowering costs for high-volume workflows.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Minimises Transition **Latency&lt;/strong&gt;**: Each state transition adds a slight delay. By managing all logic within a single Choice state, the workflow runs more efficiently due to the reduced transitions.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Against these &lt;strong&gt;tradeoffs&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Added Complexity&lt;/strong&gt;: A complex &lt;code&gt;Choice&lt;/code&gt; state with many conditions can be difficult to read, debug, and modify. It may require deeply nested logic, which makes future updates challenging.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Limited Observability&lt;/strong&gt;: If multiple conditions are combined into one state, debugging failures becomes more difficult as it is unclear which condition caused an unexpected transition.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Potential **Scaling&lt;/strong&gt;** &lt;strong&gt;Difficulty&lt;/strong&gt;: As the workflow evolves, adding more conditions to a single &lt;code&gt;Choice&lt;/code&gt; state can become unmanageable. Ultimately, this situation may &lt;em&gt;require&lt;/em&gt; breaking it up.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Final Workflows
&lt;/h3&gt;

&lt;p&gt;Finally, let's see what the workflows look like. Firstly, this workflow has separate &lt;code&gt;Choice&lt;/code&gt; states for each JSONata expression:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv5zew8tfy37rjul4vqaq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv5zew8tfy37rjul4vqaq.png" alt="stepfunctions graph Data Ingestion iTunes"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/MrDamienJones/amazonwebshark-Artefacts/blob/master/2025/2025-02-17-LowCodeS3KeyValidationWithAWSStepFunctionsAndJSONata/Data-Ingestion-iTunes.asl.json" rel="noopener noreferrer"&gt;&lt;code&gt;Data-Ingestion-iTunes&lt;/code&gt; ASL on GitHub.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, this workflow has one &lt;code&gt;Choice&lt;/code&gt; state for all JSONata expressions:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9hos4mhxe9kfojo9124x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9hos4mhxe9kfojo9124x.png" alt="stepfunctions graph Data Ingestion iTunes all"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/MrDamienJones/amazonwebshark-Artefacts/blob/master/2025/2025-02-17-LowCodeS3KeyValidationWithAWSStepFunctionsAndJSONata/Data-Ingestion-iTunes-All.asl.json" rel="noopener noreferrer"&gt;&lt;code&gt;Data-Ingestion-iTunes-All&lt;/code&gt; ASL on GitHub.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing
&lt;/h2&gt;

&lt;p&gt;To ensure my low-code JSONata expressions work as expected, I ran several tests against different S3 object keys. These tests validate:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;File Suffix (&lt;code&gt;.txt&lt;/code&gt;)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Key Content (&lt;code&gt;iTunes&lt;/code&gt;)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Date Format (&lt;code&gt;YYYY-MM-DD&lt;/code&gt;)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Suffix Validation Tests
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Test Case&lt;/th&gt;
&lt;th&gt;S3 Key&lt;/th&gt;
&lt;th&gt;Expected&lt;/th&gt;
&lt;th&gt;Actual&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;✅ &lt;strong&gt;Valid Suffix (&lt;code&gt;.txt&lt;/code&gt;)&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;"iTunes/iTunes-2025-02-01.txt"&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Proceed to &lt;strong&gt;iTunes Check&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;✅ Success → Next: &lt;strong&gt;iTunes String Check&lt;/strong&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;❌ &lt;strong&gt;Invalid Suffix (&lt;code&gt;.csv&lt;/code&gt;)&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;"iTunes/iTunes-2025-02-01.csv"&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Fail (No further checks)&lt;/td&gt;
&lt;td&gt;❌ Failure → No further checks&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;❌ &lt;strong&gt;Missing Suffix&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;"iTunes/iTunes-2025-02-01"&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Fail (No further checks)&lt;/td&gt;
&lt;td&gt;❌ Failure → No further checks&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Key Content Validation Tests
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Test Case&lt;/th&gt;
&lt;th&gt;S3 Key&lt;/th&gt;
&lt;th&gt;Expected&lt;/th&gt;
&lt;th&gt;Actual&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;✅ &lt;strong&gt;Valid "iTunes" Key&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;"iTunes/iTunes-2025-02-01.txt"&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Proceed to &lt;strong&gt;Date Check&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;✅ Success → Next: &lt;strong&gt;Date Check&lt;/strong&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;❌ &lt;strong&gt;Incorrect Case (&lt;code&gt;itunes&lt;/code&gt; instead of &lt;code&gt;iTunes&lt;/code&gt;)&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;"iTunes/itunes-2025-02-01.txt"&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Fail (No further checks)&lt;/td&gt;
&lt;td&gt;❌ Failure → No further checks&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;❌ &lt;strong&gt;Missing Key String&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;""&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Fail (No further checks)&lt;/td&gt;
&lt;td&gt;❌ Failure → No further checks&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Date Format Validation Tests
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Test Case&lt;/th&gt;
&lt;th&gt;S3 Key&lt;/th&gt;
&lt;th&gt;Expected&lt;/th&gt;
&lt;th&gt;Actual&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;✅ &lt;strong&gt;Correct Date Format (&lt;code&gt;YYYY-MM-DD&lt;/code&gt;)&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;"iTunes/iTunes-2025-02-01.txt"&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Success&lt;/strong&gt; (Validation complete)&lt;/td&gt;
&lt;td&gt;✅ Success → &lt;strong&gt;Validation complete!&lt;/strong&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;❌ &lt;strong&gt;Incorrect Date Format (Missing Day)&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;"iTunes/iTunes-2025-02.txt"&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Fail (No further checks)&lt;/td&gt;
&lt;td&gt;❌ Failure → No further checks&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;❌ &lt;strong&gt;Missing Date&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;"iTunes/iTunes.txt"&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Fail (No further checks)&lt;/td&gt;
&lt;td&gt;❌ Failure → No further checks&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Edge Case: Impossible Date
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Test Case&lt;/th&gt;
&lt;th&gt;S3 Key&lt;/th&gt;
&lt;th&gt;Expected&lt;/th&gt;
&lt;th&gt;Actual&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;⚠️ &lt;strong&gt;Impossible Date (&lt;code&gt;2025-02-31&lt;/code&gt;)&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;"iTunes/iTunes-2025-02-31.txt"&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Fail&lt;/strong&gt; (Ideally)&lt;/td&gt;
&lt;td&gt;❌ &lt;strong&gt;Unexpected Success&lt;/strong&gt; (JSONata does not validate real-world dates)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;These tests confirm that JSONata expressions can effectively validate S3 object keys based on file suffixes, key contents and date formats. However, while JSONata can check formatting (&lt;code&gt;YYYY-MM-DD&lt;/code&gt;) it does not &lt;strong&gt;validate&lt;/strong&gt; real-world dates. If strict date validation is needed then an AWS Lambda function would be required.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;In this post, I used JSONata to add low-code S3 object key validation to an AWS Step Functions state machine. This approach simplifies the validation process and reduces the reliance on more complex Lambda functions.&lt;/p&gt;

&lt;p&gt;My first impressions of JSONata are very good! It's already reduced both the number and size of Project Wolfie's Lambda functions, and there's still lots of JSONata to explore. In the meantime, these further videos by Eric Johnson explore more advanced JSONata Step Function applications:&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/aoKt7Aw2a1I"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/1Bc6jqZhUAw"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;If this post has been useful then the button below has links for contact, socials, projects and sessions:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://gravatar.com/damienjonesshark" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2dv1t3pwsh6f46n9sd5e.png" alt="SharkLinkButton 1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks for reading &lt;del&gt;^&lt;/del&gt;&lt;/p&gt;

</description>
      <category>amazoneventbridge</category>
      <category>amazons3</category>
      <category>awsstepfunctions</category>
      <category>jsonata</category>
    </item>
  </channel>
</rss>
