class Parallel (construct)
Language | Type name |
---|---|
![]() | Amazon.CDK.AWS.StepFunctions.Parallel |
![]() | github.com/aws/aws-cdk-go/awscdk/v2/awsstepfunctions#Parallel |
![]() | software.amazon.awscdk.services.stepfunctions.Parallel |
![]() | aws_cdk.aws_stepfunctions.Parallel |
![]() | aws-cdk-lib » aws_stepfunctions » Parallel |
Implements
IConstruct
, IDependable
, IChainable
, INextable
Define a Parallel state in the state machine.
A Parallel state can be used to run one or more state machines at the same time.
The Result of a Parallel state is an array of the results of its substatemachines.
Example
import { Stack } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as sfn from 'aws-cdk-lib/aws-stepfunctions';
interface MyJobProps {
jobFlavor: string;
}
class MyJob extends sfn.StateMachineFragment {
public readonly startState: sfn.State;
public readonly endStates: sfn.INextable[];
constructor(parent: Construct, id: string, props: MyJobProps) {
super(parent, id);
const choice = new sfn.Choice(this, 'Choice')
.when(sfn.Condition.stringEquals('$.branch', 'left'), new sfn.Pass(this, 'Left Branch'))
.when(sfn.Condition.stringEquals('$.branch', 'right'), new sfn.Pass(this, 'Right Branch'));
// ...
this.startState = choice;
this.endStates = choice.afterwards().endStates;
}
}
class MyStack extends Stack {
constructor(scope: Construct, id: string) {
super(scope, id);
// Do 3 different variants of MyJob in parallel
const parallel = new sfn.Parallel(this, 'All jobs')
.branch(new MyJob(this, 'Quick', { jobFlavor: 'quick' }).prefixStates())
.branch(new MyJob(this, 'Medium', { jobFlavor: 'medium' }).prefixStates())
.branch(new MyJob(this, 'Slow', { jobFlavor: 'slow' }).prefixStates());
new sfn.StateMachine(this, 'MyStateMachine', {
definitionBody: sfn.DefinitionBody.fromChainable(parallel),
});
}
}
Initializer
new Parallel(scope: Construct, id: string, props?: ParallelProps)
Parameters
- scope
Construct
- id
string
— Descriptive identifier for this chainable. - props
Parallel
Props
Construct Props
Name | Type | Description |
---|---|---|
arguments? | { [string]: any } | Parameters pass a collection of key-value pairs, either static values or JSONata expressions that select from the input. |
assign? | { [string]: any } | Workflow variables to store in this step. |
comment? | string | A comment describing this state. |
input | string | JSONPath expression to select part of the state to be the input to this state. |
output | string | JSONPath expression to select part of the state to be the output to this state. |
outputs? | any | Used to specify and transform output from the state. |
query | Query | The name of the query language used by the state. |
result | string | JSONPath expression to indicate where to inject the state's output. |
result | { [string]: any } | The JSON that will replace the state's raw result and become the effective result before ResultPath is applied. |
state | string | Optional name for this state. |
arguments?
Type:
{ [string]: any }
(optional, default: No arguments)
Parameters pass a collection of key-value pairs, either static values or JSONata expressions that select from the input.
See also: https://docs.aws.amazon.com/step-functions/latest/dg/transforming-data.html
assign?
Type:
{ [string]: any }
(optional, default: Not assign variables)
Workflow variables to store in this step.
Using workflow variables, you can store data in a step and retrieve that data in future steps.
comment?
Type:
string
(optional, default: No comment)
A comment describing this state.
inputPath?
Type:
string
(optional, default: $)
JSONPath expression to select part of the state to be the input to this state.
May also be the special value JsonPath.DISCARD, which will cause the effective input to be the empty object {}.
outputPath?
Type:
string
(optional, default: $)
JSONPath expression to select part of the state to be the output to this state.
May also be the special value JsonPath.DISCARD, which will cause the effective output to be the empty object {}.
outputs?
Type:
any
(optional, default: $states.result or $states.errorOutput)
Used to specify and transform output from the state.
When specified, the value overrides the state output default. The output field accepts any JSON value (object, array, string, number, boolean, null). Any string value, including those inside objects or arrays, will be evaluated as JSONata if surrounded by {% %} characters. Output also accepts a JSONata expression directly.
queryLanguage?
Type:
Query
(optional, default: JSONPath)
The name of the query language used by the state.
If the state does not contain a queryLanguage
field,
then it will use the query language specified in the top-level queryLanguage
field.
resultPath?
Type:
string
(optional, default: $)
JSONPath expression to indicate where to inject the state's output.
May also be the special value JsonPath.DISCARD, which will cause the state's input to become its output.
resultSelector?
Type:
{ [string]: any }
(optional, default: None)
The JSON that will replace the state's raw result and become the effective result before ResultPath is applied.
You can use ResultSelector to create a payload with values that are static or selected from the state's raw result.
stateName?
Type:
string
(optional, default: The construct ID will be used as state name)
Optional name for this state.
Properties
Name | Type | Description |
---|---|---|
end | INextable [] | Continuable states of this Chainable. |
id | string | Descriptive identifier for this chainable. |
node | Node | The tree node. |
start | State | First state of this Chainable. |
state | string | Tokenized string that evaluates to the state's ID. |
endStates
Type:
INextable
[]
Continuable states of this Chainable.
id
Type:
string
Descriptive identifier for this chainable.
node
Type:
Node
The tree node.
startState
Type:
State
First state of this Chainable.
stateId
Type:
string
Tokenized string that evaluates to the state's ID.
Methods
Name | Description |
---|---|
add | Add a recovery handler for this state. |
add | Add a prefix to the stateId of this state. |
add | Add retry configuration for this state. |
bind | Overwrites State.bindToGraph. Adds branches to the Parallel state here so that any necessary prefixes are appended first. |
branch(...branches) | Define one or more branches to run in parallel. |
next(next) | Continue normal execution with the given state. |
to | Return the Amazon States Language object for this state. |
to | Returns a string representation of this construct. |
protected validate | Validate this state. |
static json | Define a Parallel state using JSONPath in the state machine. |
static jsonata(scope, id, props?) | Define a Parallel state using JSONata in the state machine. |
addCatch(handler, props?)
public addCatch(handler: IChainable, props?: CatchProps): Parallel
Parameters
- handler
IChainable
- props
Catch
Props
Returns
Add a recovery handler for this state.
When a particular error occurs, execution will continue at the error handler instead of failing the state machine execution.
addPrefix(x)
public addPrefix(x: string): void
Parameters
- x
string
Add a prefix to the stateId of this state.
addRetry(props?)
public addRetry(props?: RetryProps): Parallel
Parameters
- props
Retry
Props
Returns
Add retry configuration for this state.
This controls if and how the execution will be retried if a particular error occurs.
bindToGraph(graph)
public bindToGraph(graph: StateGraph): void
Parameters
- graph
State
Graph
Overwrites State.bindToGraph. Adds branches to the Parallel state here so that any necessary prefixes are appended first.
branch(...branches)
public branch(...branches: IChainable[]): Parallel
Parameters
- branches
IChainable
Returns
Define one or more branches to run in parallel.
next(next)
public next(next: IChainable): Chain
Parameters
- next
IChainable
Returns
Continue normal execution with the given state.
toStateJson(topLevelQueryLanguage?)
public toStateJson(topLevelQueryLanguage?: QueryLanguage): json
Parameters
- topLevelQueryLanguage
Query
Language
Returns
json
Return the Amazon States Language object for this state.
toString()
public toString(): string
Returns
string
Returns a string representation of this construct.
protected validateState()
protected validateState(): string[]
Returns
string[]
Validate this state.
static jsonPath(scope, id, props?)
public static jsonPath(scope: Construct, id: string, props?: ParallelJsonPathProps): Parallel
Parameters
- scope
Construct
- id
string
- props
Parallel
Json Path Props
Returns
Define a Parallel state using JSONPath in the state machine.
A Parallel state can be used to run one or more state machines at the same time.
The Result of a Parallel state is an array of the results of its substatemachines.
static jsonata(scope, id, props?)
public static jsonata(scope: Construct, id: string, props?: ParallelJsonataProps): Parallel
Parameters
- scope
Construct
- id
string
- props
Parallel
Jsonata Props
Returns
Define a Parallel state using JSONata in the state machine.
A Parallel state can be used to run one or more state machines at the same time.
The Result of a Parallel state is an array of the results of its substatemachines.