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 AWS Step Functions.
Data Format
State machine data is represented by JSON text. You can provide values to a state machine 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
-
null
-
-
The output of a state becomes the input for the next state. However, you can restrict states to work on a subset of the input data by using Input and Output Processing.
State Machine Input/Output
You
can give your initial input data to an AWS Step Functions state machine in one of two ways. You
can pass the data to a
StartExecution
action when you start an execution. You can also
pass the data to the state machine from the Step Functions
consoleStartAt
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,
such
as the DescribeExecution
action. You
can view execution results on the Step Functions
console
For Express Workflows, if you enabled logging, you can retrieve results from CloudWatch Logs, or view and debug the executions in the Step Functions console. For more information, see Logging using CloudWatch Logs and Viewing and debugging executions on the Step Functions console.
You should also consider quotas related to your state machine. For more information, see Quotas
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.
-
Define the AWS 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 }); }
-
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:lambda:us-east-1:123456789012:function:Add", "End": true } } }
-
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.