State Machine Data - Amazon Step Functions
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China.

State Machine Data

State machine data takes the following forms:

  • The initial input into a state machine

  • Data passed between states

  • The output from a state machine

This section describes how state machine data is formatted and used in Amazon Step Functions.

Data Format

State machine data is represented by JSON text, so you can provide values using any data type supported by JSON.

  • Numbers in JSON text format conform to JavaScript semantics. These numbers typically correspond to double-precision IEEE-854 values.

  • The following is valid JSON text: standalone, quote-delimited strings; objects; arrays; numbers; Boolean values; and null.

  • The output of a state becomes the input into the next state. However, you can restrict states to working on a subset of the input data by using Input and Output Processing.

State Machine Input/Output

You can give Amazon Step Functions initial input data by passing it to a StartExecution action when you start an execution, or by passing initial data using the Step Functions console. Initial data is passed to the state machine's StartAt state. If no input is provided, the default is an empty object ({}).

The output of the execution is returned by the last state (terminal). This output appears as JSON text in the execution's result.

For Standard Workflows, you can retrieve execution results from the execution history using external callers (for example, in the DescribeExecution action). You can view execution results on the Step Functions console.

For Express Workflows, if you have enabled logging, you can retrieve results from CloudWatch Logs. See Logging using CloudWatch Logs for more information.

You should also consider quotas related to your state machine. For more information, see:

State Input/Output

Each state's input consists of JSON text from the preceding state or, for the StartAt state, the input into the execution. Certain flow-control states echo their input to their output.

In the following example, the state machine adds two numbers together.

  1. Define the Amazon Lambda function.

    function Add(input) { var numbers = JSON.parse(input).numbers; var total = numbers.reduce( function(previousValue, currentValue, index, array) { return previousValue + currentValue; }); return JSON.stringify({ result: total }); }
  2. Define the state machine.

    { "Comment": "An example that adds two numbers together.", "StartAt": "Add", "Version": "1.0", "TimeoutSeconds": 10, "States": { "Add": { "Type": "Task", "Resource": "arn:aws-cn:lambda:us-east-1:123456789012:function:Add", "End": true } } }
  3. Start an execution with the following JSON text.

    { "numbers": [3, 4] }

    The Add state receives the JSON text and passes it to the Lambda function.

    The Lambda function returns the result of the calculation to the state.

    The state returns the following value in its output.

    { "result": 7 }

    Because Add is also the final state in the state machine, this value is returned as the state machine's output.

    If the final state returns no output, then the state machine returns an empty object ({}).

For more information, see Input and Output Processing in Step Functions.