Bases: State
Define a Parallel state in the state machine.
A Parallel state can be used to run one or more state machines at the same time.
The Result of a Parallel state is an array of the results of its substatemachines.
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
)
scope (Construct
)
id (str
)
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
Methods
Add a recovery handler for this state.
When a particular error occurs, execution will continue at the error handler instead of failing the state machine execution.
handler (IChainable
)
errors (Optional
[Sequence
[str
]]) – Errors to recover from by going to the given state. A list of error strings to retry, which can be either predefined errors (for example Errors.NoChoiceMatched) or a self-defined error. Default: All errors
result_path (Optional
[str
]) – JSONPath expression to indicate where to inject the error data. May also be the special value DISCARD, which will cause the error data to be discarded. Default: $
Add a prefix to the stateId of this state.
x (str
)
None
Add retry configuration for this state.
This controls if and how the execution will be retried if a particular error occurs.
backoff_rate (Union
[int
, float
, None
]) – Multiplication for how much longer the wait interval gets on every retry. Default: 2
errors (Optional
[Sequence
[str
]]) – Errors to retry. A list of error strings to retry, which can be either predefined errors (for example Errors.NoChoiceMatched) or a self-defined error. Default: All errors
interval (Optional
[Duration
]) – How many seconds to wait initially before retrying. Default: Duration.seconds(1)
max_attempts (Union
[int
, float
, None
]) – How many times to retry this particular error. May be 0 to disable retry for specific errors (in case you have a catch-all retry policy). Default: 3
Overwrites State.bindToGraph. Adds branches to the Parallel state here so that any necessary prefixes are appended first.
graph (StateGraph
)
None
Define one or more branches to run in parallel.
branches (IChainable
)
Continue normal execution with the given state.
next (IChainable
)
Return the Amazon States Language object for this state.
Mapping
[Any
, Any
]
Returns a string representation of this construct.
str
Attributes
Continuable states of this Chainable.
Descriptive identifier for this chainable.
The construct tree node associated with this construct.
First state of this Chainable.
Tokenized string that evaluates to the state’s ID.
Static Methods
Return only the states that allow chaining from an array of states.
Find the set of end states states reachable through transitions from the given start state.
Find the set of states reachable through transitions from the given start state.
This does not retrieve states from within sub-graphs, such as states within a Parallel state’s branch.
Return whether the given object is a Construct.
x (Any
)
bool
Add a prefix to the stateId of all States found in a construct tree.
root (IConstruct
)
prefix (str
)
None