class StateMachineFragment
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.StepFunctions.StateMachineFragment |
Java | software.amazon.awscdk.services.stepfunctions.StateMachineFragment |
Python | aws_cdk.aws_stepfunctions.StateMachineFragment |
TypeScript (source) | @aws-cdk/aws-stepfunctions » StateMachineFragment |
Implements
IConstruct
, IConstruct
, IDependable
, IChainable
Extends
Construct
Base class for reusable state machine fragments.
Example
import { Stack } from '@aws-cdk/core';
import { Construct } from 'constructs';
import * as sfn from '@aws-cdk/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 StateMachineFragment(scope: Construct, id: string)
Parameters
- scope
Construct
- id
string
Properties
Name | Type | Description |
---|---|---|
end | INextable [] | The states to chain onto if this fragment is used. |
id | string | Descriptive identifier for this chainable. |
node | Construct | The construct tree node associated with this construct. |
start | State | The start state of this state machine fragment. |
endStates
Type:
INextable
[]
The states to chain onto if this fragment is used.
id
Type:
string
Descriptive identifier for this chainable.
node
Type:
Construct
The construct tree node associated with this construct.
startState
Type:
State
The start state of this state machine fragment.
Methods
Name | Description |
---|---|
next(next) | Continue normal execution with the given state. |
prefix | Prefix the IDs of all states in this state machine fragment. |
to | Wrap all states in this state machine fragment up into a single state. |
to | Returns a string representation of this construct. |
next(next)
public next(next: IChainable): Chain
Parameters
- next
IChainable
Returns
Continue normal execution with the given state.
States(prefix?)
prefixpublic prefixStates(prefix?: string): StateMachineFragment
Parameters
- prefix
string
— The prefix to add.
Returns
Prefix the IDs of all states in this state machine fragment.
Use this to avoid multiple copies of the state machine all having the same state IDs.
SingleState(options?)
topublic toSingleState(options?: SingleStateOptions): Parallel
Parameters
- options
Single
State Options
Returns
Wrap all states in this state machine fragment up into a single state.
This can be used to add retry or error handling onto this state machine fragment.
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]'.
String()
topublic toString(): string
Returns
string
Returns a string representation of this construct.