Skip to main content

Command Palette

Search for a command to run...

Exploring AWS Step Function Using TestState API

Updated
2 min read
Exploring AWS Step Function Using TestState API
R

I am a Lead Engineer from India. Love to blog about serverless and help teams design and develop serverless architecture. An AWS cloud practitioner. Blogs about AWS Services utilising AWS CDK, CloudFormation, Terraform.

Introduction

AWS Step Functions offers an array of testing and debugging tools. In this blog post, we'll focus on the TestState API.

TestState API helps us to test a single state in the state machine workflow. So, we can test a state without creating a state machine and execute the complete flow. This helps resolve common errors such as path issues, and input/output issues at the development time and at a fast pace.

Supported States

The following states are supported for TestState.

  • Pass

  • Wait

  • Task

  • Choice

  • Succeed

  • Fail

Informative levels

Step Functions offers three distinct inspection levels: INFO, DEBUG, and TRACE. The different inspection levels, provide us the right amount of detail to suit our debugging and validation needs.

  • INFO: At this level, we receive essential information about the state execution, including the status and the next state to transition to.

  • DEBUG: At this level, it provides additional insights into the state execution. Beyond the status and next state, you gain access to intermediate details, especially useful when using input and output data processing filters like InputPath or ResultPath.

  • TRACE: At this level, it not only includes the status and next state but also provides deep into the intermediate and final data processing results.

Using AWS CLI with TestState

We can use AWS CLI with TestState for testing each state of the state machine in silo.

Suppose, we have a passstate in our Stepfunction as shown below.

{
      "Type": "Pass",
      "Next": "Second State",
      "Parameters": {
        "payload.$": "$.customer.firstName"
      }
    }

To test this state, we can use below AWS CLI command

aws stepfunctions test-state \
    --definition '{
      "Type": "Pass",
      "Next": "Second State",
      "Parameters": {
        "payload.$": "$.customer.firstName"
      }
    }' \
    --role-arn arn:aws:iam::1234567843:role/example \
    --input '{"customer": {
        "firstName": "rahul",
        "lastName": "lokurte"
    }
    }'

The output is as shown below.

{
  "nextState": "Second State",
  "output": "{\"payload\":\"rahul\"}",
  "status": "SUCCEEDED"
}

Conclusion

As seen in this short blog, we can use the TestState API to test the individual states in a state machine which opens up a lot of opportunities for testing the step functions thoroughly.

More from this blog

R

Rahul Lokurte Blog

34 posts

I'm a Devops and Cloud Engineer with 10 years of experience designing and building applications using containers and serverless technologies. Love blogging about AWS