aws-cdk-lib.aws_stepfunctions.Chain

class Chain

LanguageType name
.NETAmazon.CDK.AWS.StepFunctions.Chain
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awsstepfunctions#Chain
Javasoftware.amazon.awscdk.services.stepfunctions.Chain
Pythonaws_cdk.aws_stepfunctions.Chain
TypeScript (source)aws-cdk-lib » aws_stepfunctions » Chain

Implements IChainable

A collection of states to chain onto.

A Chain has a start and zero or more chainable ends. If there are zero ends, calling next() on the Chain will fail.

Example

// Define a state machine with one Pass state
const child = new sfn.StateMachine(this, 'ChildStateMachine', {
  definition: sfn.Chain.start(new sfn.Pass(this, 'PassState')),
});

// Include the state machine in a Task state with callback pattern
const task = new tasks.StepFunctionsStartExecution(this, 'ChildTask', {
  stateMachine: child,
  integrationPattern: sfn.IntegrationPattern.WAIT_FOR_TASK_TOKEN,
  input: sfn.TaskInput.fromObject({
    token: sfn.JsonPath.taskToken,
    foo: 'bar',
  }),
  name: 'MyExecutionName',
});

// Define a second state machine with the Task state above
new sfn.StateMachine(this, 'ParentStateMachine', {
  definition: task,
});

Properties

NameTypeDescription
endStatesINextable[]The chainable end state(s) of this chain.
idstringIdentify this Chain.
startStateStateThe start state of this chain.

endStates

Type: INextable[]

The chainable end state(s) of this chain.


id

Type: string

Identify this Chain.


startState

Type: State

The start state of this chain.

Methods

NameDescription
next(next)Continue normal execution with the given state.
toSingleState(id, props?)Return a single state that encompasses all states in the chain.
static custom(startState, endStates, lastAdded)Make a Chain with specific start and end states, and a last-added Chainable.
static sequence(start, next)Make a Chain with the start from one chain and the ends from another.
static start(state)Begin a new Chain from one chainable.

next(next)

public next(next: IChainable): Chain

Parameters

  • next IChainable

Returns

  • Chain

Continue normal execution with the given state.


toSingleState(id, props?)

public toSingleState(id: string, props?: ParallelProps): Parallel

Parameters

  • id string
  • props ParallelProps

Returns

  • Parallel

Return a single state that encompasses all states in the chain.

This can be used to add error handling to a sequence of states.

Be aware that this changes the result of the inner state machine to be an array with the result of the state machine in it. Adjust your paths accordingly. For example, change 'outputPath' to '$[0]'.


static custom(startState, endStates, lastAdded)

public static custom(startState: State, endStates: INextable[], lastAdded: IChainable): Chain

Parameters

  • startState State
  • endStates INextable[]
  • lastAdded IChainable

Returns

  • Chain

Make a Chain with specific start and end states, and a last-added Chainable.


static sequence(start, next)

public static sequence(start: IChainable, next: IChainable): Chain

Parameters

  • start IChainable
  • next IChainable

Returns

  • Chain

Make a Chain with the start from one chain and the ends from another.


static start(state)

public static start(state: IChainable): Chain

Parameters

  • state IChainable

Returns

  • Chain

Begin a new Chain from one chainable.