Skip to content
v2.274.0

Chain Class ​

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 ​

ts
const map = new sfn.Map(this, 'Map State', {
  maxConcurrency: 1,
  itemsPath: sfn.JsonPath.stringAt('$.inputForMap'),
  itemSelector: {
    item: sfn.JsonPath.stringAt('$$.Map.Item.Value'),
  },
  resultPath: '$.mapOutput',
});

// The Map iterator can contain a IChainable, which can be an individual or multiple steps chained together.
// Below example is with a Choice and Pass step
const choice = new sfn.Choice(this, 'Choice');
const condition1 = sfn.Condition.stringEquals('$.item.status', 'SUCCESS');
const step1 = new sfn.Pass(this, 'Step1');
const step2 = new sfn.Pass(this, 'Step2');
const finish = new sfn.Pass(this, 'Finish');

const definition = choice
    .when(condition1, step1)
    .otherwise(step2)
    .afterwards()
    .next(finish);

map.itemProcessor(definition);

Properties ​

endStatesINextable[]end_statestyping.List[INextable]endStatesList<INextable>EndStatesINextable[]EndStates*[]INextablerequired#
The chainable end state(s) of this chain.
idstringidstridStringIdstringId*stringrequired#
Identify this Chain.
startStateStatestart_stateStatestartStateStateStartStateStateStartStateStaterequired#
The start state of this chain.

Methods ​

custom(startState: State, endStates: INextable[], lastAdded: IChainable): Chain // chainable@staticmethod def custom(start_state: State, end_states: typing.List[INextable], last_added: IChainable) -> Chainpublic static Chain custom(State startState, List<INextable> endStates, IChainable lastAdded)public static Chain Custom(State startState, INextable[] endStates, IChainable lastAdded)func Custom(StartState State, EndStates *[]INextable, LastAdded IChainable) Chainstatic#
Make a Chain with specific start and end states, and a last-added Chainable.
sequence(start: IChainable, next: IChainable): Chain // chainable@staticmethod def sequence(start: IChainable, next: IChainable) -> Chainpublic static Chain sequence(IChainable start, IChainable next)public static Chain Sequence(IChainable start, IChainable next)func Sequence(Start IChainable, Next IChainable) Chainstatic#
Make a Chain with the start from one chain and the ends from another.
start(state: IChainable): Chain // chainable@staticmethod def start(state: IChainable) -> Chainpublic static Chain start(IChainable state)public static Chain Start(IChainable state)func Start(State IChainable) Chainstatic#
Begin a new Chain from one chainable.
toSingleState(id: string, props?: ParallelProps): Paralleldef to_single_state(self, id: str, props: typing.Optional[ParallelProps] = None) -> Parallelpublic Parallel toSingleState(String id, ParallelProps props)public Parallel ToSingleState(string id, ParallelProps? props = null)func ToSingleState(Id *string, Props ParallelProps) Parallel#
Return a single state that encompasses all states in the chain.
notes

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]'.