Choice
- class aws_cdk.aws_stepfunctions.Choice(scope, id, *, comment=None, input_path=None, output_path=None, state_name=None)
Bases:
State
Define a Choice in the state machine.
A choice state can be used to make decisions based on the execution state.
- ExampleMetadata:
infused
Example:
map = sfn.Map(self, "Map State", max_concurrency=1, items_path=sfn.JsonPath.string_at("$.inputForMap"), item_selector={ "item": sfn.JsonPath.string_at("$.Map.Item.Value") }, result_path="$.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 choice = sfn.Choice(self, "Choice") condition1 = sfn.Condition.string_equals("$.item.status", "SUCCESS") step1 = sfn.Pass(self, "Step1") step2 = sfn.Pass(self, "Step2") finish = sfn.Pass(self, "Finish") definition = choice.when(condition1, step1).otherwise(step2).afterwards().next(finish) map.item_processor(definition)
- Parameters:
scope (
Construct
) –id (
str
) – Descriptive identifier for this chainable.comment (
Optional
[str
]) – An optional description for this state. Default: No commentinput_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: $state_name (
Optional
[str
]) – Optional name for this state. Default: - The construct ID will be used as state name
Methods
- add_prefix(x)
Add a prefix to the stateId of this state.
- Parameters:
x (
str
) –- Return type:
None
- afterwards(*, include_error_handlers=None, include_otherwise=None)
Return a Chain that contains all reachable end states from this Choice.
Use this to combine all possible choice paths back.
- Parameters:
include_error_handlers (
Optional
[bool
]) – Whether to include error handling states. If this is true, all states which are error handlers (added through ‘onError’) and states reachable via error handlers will be included as well. Default: falseinclude_otherwise (
Optional
[bool
]) – Whether to include the default/otherwise transition for the current Choice state. If this is true and the current Choice does not have a default outgoing transition, one will be added included when .next() is called on the chain. Default: false
- Return type:
- bind_to_graph(graph)
Register this state as part of the given graph.
Don’t call this. It will be called automatically when you work with states normally.
- Parameters:
graph (
StateGraph
) –- Return type:
None
- otherwise(def_)
If none of the given conditions match, continue execution with the given state.
If no conditions match and no otherwise() has been given, an execution error will be raised.
- Parameters:
def –
- Return type:
- to_state_json()
Return the Amazon States Language object for this state.
- Return type:
Mapping
[Any
,Any
]
- to_string()
Returns a string representation of this construct.
- Return type:
str
- when(condition, next, *, comment=None)
If the given condition matches, continue execution with the given state.
- Parameters:
condition (
Condition
) –next (
IChainable
) –comment (
Optional
[str
]) – An optional description for the choice transition. Default: No comment
- Return type:
Attributes
- end_states
Continuable states of this Chainable.
- id
Descriptive identifier for this chainable.
- node
The tree node.
- start_state
First state of this Chainable.
- state_id
Tokenized string that evaluates to the state’s ID.
Static Methods
- classmethod filter_nextables(states)
Return only the states that allow chaining from an array of states.
- classmethod find_reachable_end_states(start, *, include_error_handlers=None)
Find the set of end states states reachable through transitions from the given start state.
- classmethod find_reachable_states(start, *, include_error_handlers=None)
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.
- classmethod is_construct(x)
Checks if
x
is a construct.Use this method instead of
instanceof
to properly detectConstruct
instances, even when the construct library is symlinked.Explanation: in JavaScript, multiple copies of the
constructs
library on disk are seen as independent, completely different libraries. As a consequence, the classConstruct
in each copy of theconstructs
library is seen as a different class, and an instance of one class will not test asinstanceof
the other class.npm install
will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of theconstructs
library can be accidentally installed, andinstanceof
will behave unpredictably. It is safest to avoid usinginstanceof
, and using this type-testing method instead.- Parameters:
x (
Any
) – Any object.- Return type:
bool
- Returns:
true if
x
is an object created from a class which extendsConstruct
.
- classmethod prefix_states(root, prefix)
Add a prefix to the stateId of all States found in a construct tree.
- Parameters:
root (
IConstruct
) –prefix (
str
) –
- Return type:
None