aws-cdk-lib.aws_stepfunctions.Parallel

class Parallel (construct)

LanguageType name
.NETAmazon.CDK.AWS.StepFunctions.Parallel
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awsstepfunctions#Parallel
Javasoftware.amazon.awscdk.services.stepfunctions.Parallel
Pythonaws_cdk.aws_stepfunctions.Parallel
TypeScript (source)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', {
      definition: parallel,
    });
  }
}

Initializer

new Parallel(scope: Construct, id: string, props?: ParallelProps)

Parameters

  • scope Construct
  • id string — Descriptive identifier for this chainable.
  • props ParallelProps

Construct Props

NameTypeDescription
comment?stringAn optional description for this state.
inputPath?stringJSONPath expression to select part of the state to be the input to this state.
outputPath?stringJSONPath expression to select part of the state to be the output to this state.
resultPath?stringJSONPath expression to indicate where to inject the state's output.
resultSelector?{ [string]: any }The JSON that will replace the state's raw result and become the effective result before ResultPath is applied.

comment?

Type: string (optional, default: No comment)

An optional description for 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 {}.


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.

See also: https://docs.aws.amazon.com/step-functions/latest/dg/input-output-inputpath-params.html#input-output-resultselector

Properties

NameTypeDescription
endStatesINextable[]Continuable states of this Chainable.
idstringDescriptive identifier for this chainable.
nodeNodeThe tree node.
startStateStateFirst state of this Chainable.
stateIdstringTokenized 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

NameDescription
addCatch(handler, props?)Add a recovery handler for this state.
addPrefix(x)Add a prefix to the stateId of this state.
addRetry(props?)Add retry configuration for this state.
bindToGraph(graph)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.
toStateJson()Return the Amazon States Language object for this state.
toString()Returns a string representation of this construct.
protected validateState()Validate this state.

addCatch(handler, props?)

public addCatch(handler: IChainable, props?: CatchProps): Parallel

Parameters

  • handler IChainable
  • props CatchProps

Returns

  • Parallel

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 RetryProps

Returns

  • Parallel

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 StateGraph

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

  • Parallel

Define one or more branches to run in parallel.


next(next)

public next(next: IChainable): Chain

Parameters

  • next IChainable

Returns

  • Chain

Continue normal execution with the given state.


toStateJson()

public toStateJson(): json

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.