CustomState
- class aws_cdk.aws_stepfunctions.CustomState(scope, id, *, state_json)
Bases:
State
State defined by supplying Amazon States Language (ASL) in the state machine.
- ExampleMetadata:
infused
Example:
import aws_cdk.aws_dynamodb as dynamodb # create a table table = dynamodb.Table(self, "montable", partition_key=dynamodb.Attribute( name="id", type=dynamodb.AttributeType.STRING ) ) final_status = sfn.Pass(self, "final step") # States language JSON to put an item into DynamoDB # snippet generated from https://docs.aws.amazon.com/step-functions/latest/dg/tutorial-code-snippet.html#tutorial-code-snippet-1 state_json = { "Type": "Task", "Resource": "arn:aws:states:::dynamodb:putItem", "Parameters": { "TableName": table.table_name, "Item": { "id": { "S": "MyEntry" } } }, "ResultPath": null } # custom state which represents a task to insert data into DynamoDB custom = sfn.CustomState(self, "my custom task", state_json=state_json ) # catch errors with addCatch error_handler = sfn.Pass(self, "handle failure") custom.add_catch(error_handler) # retry the task if something goes wrong custom.add_retry( errors=[sfn.Errors.ALL], interval=Duration.seconds(10), max_attempts=5 ) chain = sfn.Chain.start(custom).next(final_status) sm = sfn.StateMachine(self, "StateMachine", definition_body=sfn.DefinitionBody.from_chainable(chain), timeout=Duration.seconds(30), comment="a super cool state machine" ) # don't forget permissions. You need to assign them table.grant_write_data(sm)
- Parameters:
scope (
Construct
) –id (
str
) – Descriptive identifier for this chainable.state_json (
Mapping
[str
,Any
]) – Amazon States Language (JSON-based) definition of the state.
Methods
- add_catch(handler, *, assign=None, errors=None, outputs=None, result_path=None)
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.
- Parameters:
handler (
IChainable
) –assign (
Optional
[Mapping
[str
,Any
]]) – Workflow variables to store in this step. Using workflow variables, you can store data in a step and retrieve that data in future steps. Default: - Not assign variableserrors (
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 errorsoutputs (
Any
) – This option for JSONata only. When you use JSONPath, then the state ignores this property. Used to specify and transform output from the state. When specified, the value overrides the state output default. The output field accepts any JSON value (object, array, string, number, boolean, null). Any string value, including those inside objects or arrays, will be evaluated as JSONata if surrounded by {% %} characters. Output also accepts a JSONata expression directly. Default: - $states.result or $states.errorOutputresult_path (
Optional
[str
]) – JSONPath expression to indicate where to inject the error data. May also be the special value JsonPath.DISCARD, which will cause the error data to be discarded. Default: $
- Return type:
- add_prefix(x)
Add a prefix to the stateId of this state.
- Parameters:
x (
str
) –- Return type:
None
- add_retry(*, backoff_rate=None, errors=None, interval=None, jitter_strategy=None, max_attempts=None, max_delay=None)
Add retry configuration for this state.
This controls if and how the execution will be retried if a particular error occurs.
- Parameters:
backoff_rate (
Union
[int
,float
,None
]) – Multiplication for how much longer the wait interval gets on every retry. Default: 2errors (
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 errorsinterval (
Optional
[Duration
]) – How many seconds to wait initially before retrying. Default: Duration.seconds(1)jitter_strategy (
Optional
[JitterType
]) – Introduces a randomization over the retry interval. Default: - No jitter strategymax_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: 3max_delay (
Optional
[Duration
]) – Maximum limit on retry interval growth during exponential backoff. Default: - No max delay
- 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
- next(next)
Continue normal execution with the given state.
- Parameters:
next (
IChainable
) –- Return type:
- to_state_json(query_language=None)
Returns the Amazon States Language object for this state.
- Parameters:
query_language (
Optional
[QueryLanguage
]) –- Return type:
Mapping
[Any
,Any
]
- to_string()
Returns a string representation of this construct.
- Return type:
str
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