To pass data, a state in CloudFlow accepts inputs of the previous state and then returns outputs and passes outputs to the next state. This topic describes the inputs and outputs in workflows.
Flows and states
Data passing among multiple states in a workflow is similar to data passing in a functional programming language. States in CloudFlow are similar to functions in programs. The states accept inputs, return outputs, and store outputs in contexts. Each workflow execution involves the input and output of the workflow execution, and the input and output of states in the workflow execution.
Inputs and outputs must be JSON objects. The input or output of a workflow state cannot exceed 64 KiB in size. If the input or output of a workflow state exceeds 64 KiB in size, the workflow fails to be executed.
Input and output of executions
Input of executions: Input of executions is also called input of workflows. Each time when you want to execute a workflow, you must provide input for the execution. You can use the
$Context.Execution.Input
system expression to access the input of the execution.Output of executions: Output of executions is also called output of workflows. Each time a workflow is executed, an output is generated. The current workflow orchestration specification does not allow you to use system variables to access output of workflow executions during workflow orchestration.
Input and output of states
Input of states: During workflow orchestration, you can use the
$Context.Current.Input
system expression or the$Input
shortcut expression to access the input of the current state.Output of states: During workflow orchestration, you can use the
$Context.Current.Output
system expression or the$Output
shortcut expression to access the output of the current state. However, the$Output
shortcut expression can be used only in the scopes of output constructors.
System expressions that can be used in constructors
$Context: The lifecycle of $Context is the same as the whole execution period of the workflow. For more information about
$Context
, see Data passing.$Input: The lifecycle of $Input starts when the workflow enters the state and ends when the workflow exits the state. $Input is the simple form of
$Context.Current.Input
.$Output: The lifecycle of $Output starts when the workflow enters the task invocation returning state, and ends when the workflow exits the state. $Output is the simple form of
$Context.Current.Output
.
In the preceding figure, $Input
= InputConstructor indicates that within the scope, after an input is constructed by using the input constructor, the constructed result is assigned to the $Input
variable. Similarly, after the Task is invoked, the result returned by the Task is assigned to the $Output
variable. If the Task is invoked in asynchronous callback mode, the $Output
value is the returned result of the callback. In this case, the workflow proceeds. $Output=
OutputConstructor indicates that within the scope, after an output is constructed by using the output constructor, the constructed result is assigned to the $Output
variable.
State InputConstructor
You can use the following system variables in the state InputConstructor:
$Context
$Input
The expressions of InputConstructor are different from the conditional expressions of Choice states. Conditional expressions can return only Boolean values. The expressions of InputConstructor can return any value.
Type: StateMachine
Name: InputConstructExample
SpecVersion: v1
StartAt: InvokeFunction
States:
- Type: Task
Name: InvokeFunction
Action: FC:InvokeFunction
TaskMode: RequestComplete
InputConstructor:
FieldA.$: $Context.Execution.Input
FieldB: World
Parameters:
resourceArn: >-
acs:fc:cn-hangzhou:123456:services/helloworld.LATEST/functions/helloworld
invocationType: Sync
body.$: $Input
End: true
In the preceding example, the data structure of InputConstructor is Map[String]Any. In the data structure, FieldA: 123
indicates the assignment action. For information about the built-in functions that can be used in constructors, see Built-in functions.
State OutputConstructor
You can use the following system variables in the state OutputConstructor:
$Context
$Input
$Output
If a state is executed, you can use the $Output variable in OutputConstructor to specify the output of the state. Then, the system uses the output to perform subsequent operations.
Compared with InputConstructor, OutputConstructor is executed at a different time and allows you to use more variables in context expressions. For example, in InputConstructor of the states of a workflow, you can use only the $Context
and $Input
variables. In OutputConstructor of the states of the workflow, you can use the $Output
variable to specify the outputs of tasks. If you want to use a reserved word that starts with $
, you must suffix .$
to the key of the constructor supported by the Flow Definition Language (FDL). Otherwise, the reserved word is processed as a string.
Type: StateMachine
Name: OutputConstructExample
SpecVersion: v1
StartAt: InvokeFunction
States:
- Type: Task
Name: InvokeFunction
Action: FC:InvokeFunction
TaskMode: RequestComplete
Parameters:
resourceArn: >-
acs:fc:cn-hangzhou:123456:services/helloworld.LATEST/functions/helloworld
invocationType: Sync
body.$: $Input
OutputConstructor:
returnID.$: uuid()
functionResult.$: $Output
functionResultStr.$: jsonToString($Output)
executionInput.$: $Context.Execution.Input
lastOutput.$: $Input
End: true
In the preceding example, the data structure of OutputConstructor is map[string]any. The values of $Context, $Input, and $Output are assigned. The input of the workflow execution, the output of the previous state, and the output of the current state are put together into one output result.
Built-in functions can be used when you construct inputs and outputs. You must suffix .$
to the key of the constructor supported by the FDL to indicate that the corresponding value is an expression. The expression must be parsed. If you do not suffix .$ to the key of the constructor, the value is processed as a string. A maximum of 10
layers of nested built-in functions are supported in input and output construction.