StateMachineFragment

class aws_cdk.aws_stepfunctions.StateMachineFragment(scope, id)

Bases: Construct

Base class for reusable state machine fragments.

ExampleMetadata:

nofixture infused

Example:

from aws_cdk.core import Stack
from constructs import Construct
import aws_cdk.aws_stepfunctions as sfn

class MyJob(sfn.StateMachineFragment):

    def __init__(self, parent, id, *, jobFlavor):
        super().__init__(parent, id)

        choice = sfn.Choice(self, "Choice").when(sfn.Condition.string_equals("$.branch", "left"), sfn.Pass(self, "Left Branch")).when(sfn.Condition.string_equals("$.branch", "right"), sfn.Pass(self, "Right Branch"))

        # ...

        self.start_state = choice
        self.end_states = choice.afterwards().end_states

class MyStack(Stack):
    def __init__(self, scope, id):
        super().__init__(scope, id)
        # Do 3 different variants of MyJob in parallel
        parallel = sfn.Parallel(self, "All jobs").branch(MyJob(self, "Quick", job_flavor="quick").prefix_states()).branch(MyJob(self, "Medium", job_flavor="medium").prefix_states()).branch(MyJob(self, "Slow", job_flavor="slow").prefix_states())

        sfn.StateMachine(self, "MyStateMachine",
            definition=parallel
        )
Parameters:

Methods

next(next)

Continue normal execution with the given state.

Parameters:

next (IChainable) –

Return type:

Chain

prefix_states(prefix=None)

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.

Parameters:

prefix (Optional[str]) – The prefix to add. Will use construct ID by default.

Return type:

StateMachineFragment

to_single_state(*, prefix_states=None, state_id=None, comment=None, input_path=None, output_path=None, result_path=None, result_selector=None)

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

Parameters:
  • prefix_states (Optional[str]) – String to prefix all stateIds in the state machine with. Default: stateId

  • state_id (Optional[str]) – ID of newly created containing state. Default: Construct ID of the StateMachineFragment

  • comment (Optional[str]) – An optional description for this state. Default: No comment

  • input_path (Optional[str]) – 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 {}. Default: $

  • output_path (Optional[str]) – 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 {}. Default: $

  • result_path (Optional[str]) – 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. Default: $

  • result_selector (Optional[Mapping[str, Any]]) – 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. Default: - None

Return type:

Parallel

to_string()

Returns a string representation of this construct.

Return type:

str

Attributes

end_states

The states to chain onto if this fragment is used.

id

Descriptive identifier for this chainable.

node

The construct tree node associated with this construct.

start_state

The start state of this state machine fragment.

Static Methods

classmethod is_construct(x)

Return whether the given object is a Construct.

Parameters:

x (Any) –

Return type:

bool