Choice
- class aws_cdk.aws_stepfunctions.Choice(scope, id, *, comment=None, input_path=None, output_path=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:
import aws_cdk.aws_lambda as lambda_ # submit_lambda: lambda.Function # get_status_lambda: lambda.Function submit_job = tasks.LambdaInvoke(self, "Submit Job", lambda_function=submit_lambda, # Lambda's result is in the attribute `Payload` output_path="$.Payload" ) wait_x = sfn.Wait(self, "Wait X Seconds", time=sfn.WaitTime.seconds_path("$.waitSeconds") ) get_status = tasks.LambdaInvoke(self, "Get Job Status", lambda_function=get_status_lambda, # Pass just the field named "guid" into the Lambda, put the # Lambda's result in a field called "status" in the response input_path="$.guid", output_path="$.Payload" ) job_failed = sfn.Fail(self, "Job Failed", cause="AWS Batch Job Failed", error="DescribeJob returned FAILED" ) final_status = tasks.LambdaInvoke(self, "Get Final Job Status", lambda_function=get_status_lambda, # Use "guid" field as input input_path="$.guid", output_path="$.Payload" ) definition = submit_job.next(wait_x).next(get_status).next(sfn.Choice(self, "Job Complete?").when(sfn.Condition.string_equals("$.status", "FAILED"), job_failed).when(sfn.Condition.string_equals("$.status", "SUCCEEDED"), final_status).otherwise(wait_x)) sfn.StateMachine(self, "StateMachine", definition=definition, timeout=Duration.minutes(5) )
- Parameters:
scope (
Construct
)id (
str
)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 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 DISCARD, which will cause the effective output to be the empty object {}. Default: $
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)
If the given condition matches, continue execution with the given state.
- Parameters:
condition (
Condition
)next (
IChainable
)
- Return type:
Attributes
- end_states
Continuable states of this Chainable.
- id
Descriptive identifier for this chainable.
- node
The construct tree node associated with this construct.
- 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)
Return whether the given object is a Construct.
- Parameters:
x (
Any
)- Return type:
bool
- 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