class StateMachineFragment
Language | Type name |
---|---|
![]() | Amazon.CDK.AWS.StepFunctions.StateMachineFragment |
![]() | github.com/aws/aws-cdk-go/awscdk/v2/awsstepfunctions#StateMachineFragment |
![]() | software.amazon.awscdk.services.stepfunctions.StateMachineFragment |
![]() | aws_cdk.aws_stepfunctions.StateMachineFragment |
![]() | aws-cdk-lib » aws_stepfunctions » StateMachineFragment |
Implements
IConstruct
, IDependable
, IChainable
Extends
Construct
Base class for reusable state machine fragments.
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 StateMachineFragment(scope: Construct, id: string)
Parameters
- scope
Construct
— The scope in which to define this construct. - id
string
— The scoped construct ID.
Creates a new construct node.
Properties
Name | Type | Description |
---|---|---|
end | INextable [] | The states to chain onto if this fragment is used. |
id | string | Descriptive identifier for this chainable. |
node | Node | The tree node. |
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:
Node
The tree node.
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.
prefixStates(prefix?)
public 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.
toSingleState(options?)
public 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]'.
toString()
public toString(): string
Returns
string
Returns a string representation of this construct.