class CustomState (construct)
| Language | Type name |
|---|---|
.NET | Amazon.CDK.AWS.StepFunctions.CustomState |
Go | github.com/aws/aws-cdk-go/awscdk/v2/awsstepfunctions#CustomState |
Java | software.amazon.awscdk.services.stepfunctions.CustomState |
Python | aws_cdk.aws_stepfunctions.CustomState |
TypeScript (source) | aws-cdk-lib » aws_stepfunctions » CustomState |
Implements
IConstruct, IDependable, IChainable, INextable
State defined by supplying Amazon States Language (ASL) in the state machine.
Example
import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';
// create a table
const table = new dynamodb.Table(this, 'montable', {
partitionKey: {
name: 'id',
type: dynamodb.AttributeType.STRING,
},
});
const finalStatus = new sfn.Pass(this, '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
const stateJson = {
Type: 'Task',
Resource: 'arn:aws:states:::dynamodb:putItem',
Parameters: {
TableName: table.tableName,
Item: {
id: {
S: 'MyEntry',
},
},
},
ResultPath: null,
};
// custom state which represents a task to insert data into DynamoDB
const custom = new sfn.CustomState(this, 'my custom task', {
stateJson,
});
// catch errors with addCatch
const errorHandler = new sfn.Pass(this, 'handle failure');
custom.addCatch(errorHandler);
// retry the task if something goes wrong
custom.addRetry({
errors: [sfn.Errors.ALL],
interval: Duration.seconds(10),
maxAttempts: 5,
});
const chain = sfn.Chain.start(custom)
.next(finalStatus);
const sm = new sfn.StateMachine(this, 'StateMachine', {
definitionBody: sfn.DefinitionBody.fromChainable(chain),
timeout: Duration.seconds(30),
comment: 'a super cool state machine',
});
// don't forget permissions. You need to assign them
table.grantWriteData(sm);
Initializer
new CustomState(scope: Construct, id: string, props: CustomStateProps)
Parameters
- scope
Construct - id
string— Descriptive identifier for this chainable. - props
CustomState Props
Construct Props
| Name | Type | Description |
|---|---|---|
| state | { [string]: any } | Amazon States Language (JSON-based) definition of the state. |
stateJson
Type:
{ [string]: any }
Amazon States Language (JSON-based) definition of the state.
Properties
| Name | Type | Description |
|---|---|---|
| end | INextable[] | Continuable states of this Chainable. |
| id | string | Descriptive identifier for this chainable. |
| node | Node | The tree node. |
| start | State | First state of this Chainable. |
| state | string | Tokenized string that evaluates to the state's ID. |
endStates
Type:
INextable[]
Continuable states of this Chainable.
id
Type:
string
Descriptive identifier for this chainable.
node
Type:
Node
The tree node.
startState
Type:
State
First state of this Chainable.
stateId
Type:
string
Tokenized string that evaluates to the state's ID.
Methods
| Name | Description |
|---|---|
| add | Add a recovery handler for this state. |
| add | Add a prefix to the stateId of this state. |
| add | Add retry configuration for this state. |
| bind | Register this state as part of the given graph. |
| next(next) | Continue normal execution with the given state. |
| to | Returns the Amazon States Language object for this state. |
| to | Returns a string representation of this construct. |
| with(...mixins) | Applies one or more mixins to this construct. |
addCatch(handler, props?)
public addCatch(handler: IChainable, props?: CatchProps): CustomState
Parameters
- handler
IChainable - props
CatchProps
Returns
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.
addPrefix(x)
public addPrefix(x: string): void
Parameters
- x
string
Add a prefix to the stateId of this state.
addRetry(props?)
public addRetry(props?: RetryProps): CustomState
Parameters
- props
RetryProps
Returns
Add retry configuration for this state.
This controls if and how the execution will be retried if a particular error occurs.
bindToGraph(graph)
public bindToGraph(graph: StateGraph): void
Parameters
- graph
StateGraph
Register this state as part of the given graph.
Don't call this. It will be called automatically when you work with states normally.
next(next)
public next(next: IChainable): Chain
Parameters
- next
IChainable
Returns
Continue normal execution with the given state.
toStateJson(queryLanguage?)
public toStateJson(queryLanguage?: QueryLanguage): json
Parameters
- queryLanguage
QueryLanguage
Returns
json
Returns the Amazon States Language object for this state.
toString()
public toString(): string
Returns
string
Returns a string representation of this construct.
with(...mixins)
public with(...mixins: IMixin[]): IConstruct
Parameters
- mixins
IMixin— The mixins to apply.
Returns
Applies one or more mixins to this construct.
Mixins are applied in order. The list of constructs is captured at the
start of the call, so constructs added by a mixin will not be visited.
Use multiple with() calls if subsequent mixins should apply to added
constructs.

.NET
Go
Java
Python
TypeScript (