Errors Class
Predefined error strings Error names in Amazon States Language - https://states-language.net/spec.html#appendix-a Error handling in Step Functions - https://docs.aws.amazon.com/step-functions/latest/dg/concepts-error-handling.html.
Example
ts
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);
python
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)
java
import software.amazon.awscdk.services.dynamodb.*;
// create a table
Table table = Table.Builder.create(this, "montable")
.partitionKey(Attribute.builder()
.name("id")
.type(AttributeType.STRING)
.build())
.build();
Pass finalStatus = new 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
Map<String, Object> stateJson = Map.of(
"Type", "Task",
"Resource", "arn:aws:states:::dynamodb:putItem",
"Parameters", Map.of(
"TableName", table.getTableName(),
"Item", Map.of(
"id", Map.of(
"S", "MyEntry"))),
"ResultPath", null);
// custom state which represents a task to insert data into DynamoDB
CustomState custom = CustomState.Builder.create(this, "my custom task")
.stateJson(stateJson)
.build();
// catch errors with addCatch
Pass errorHandler = new Pass(this, "handle failure");
custom.addCatch(errorHandler);
// retry the task if something goes wrong
custom.addRetry(RetryProps.builder()
.errors(List.of(Errors.ALL))
.interval(Duration.seconds(10))
.maxAttempts(5)
.build());
Chain chain = Chain.start(custom).next(finalStatus);
StateMachine sm = StateMachine.Builder.create(this, "StateMachine")
.definitionBody(DefinitionBody.fromChainable(chain))
.timeout(Duration.seconds(30))
.comment("a super cool state machine")
.build();
// don't forget permissions. You need to assign them
table.grantWriteData(sm);
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.DynamoDB;
// create a table
var table = new Table(this, "montable", new TableProps {
PartitionKey = new Attribute {
Name = "id",
Type = AttributeType.STRING
}
});
var finalStatus = new 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
IDictionary<string, object> stateJson = new Dictionary<string, object> {
{ "Type", "Task" },
{ "Resource", "arn:aws:states:::dynamodb:putItem" },
{ "Parameters", new Dictionary<string, object> {
{ "TableName", table.TableName },
{ "Item", new Dictionary<string, IDictionary<string, string>> {
{ "id", new Dictionary<string, string> {
{ "S", "MyEntry" }
} }
} }
} },
{ "ResultPath", null }
};
// custom state which represents a task to insert data into DynamoDB
var custom = new CustomState(this, "my custom task", new CustomStateProps {
StateJson = stateJson
});
// catch errors with addCatch
var errorHandler = new Pass(this, "handle failure");
custom.AddCatch(errorHandler);
// retry the task if something goes wrong
custom.AddRetry(new RetryProps {
Errors = new [] { Errors.ALL },
Interval = Duration.Seconds(10),
MaxAttempts = 5
});
var chain = Chain.Start(custom).Next(finalStatus);
var sm = new StateMachine(this, "StateMachine", new StateMachineProps {
DefinitionBody = 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);
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"
// create a table
table := dynamodb.NewTable(this, jsii.String("montable"), &TableProps{
PartitionKey: &Attribute{
Name: jsii.String("id"),
Type: dynamodb.AttributeType_STRING,
},
})
finalStatus := sfn.NewPass(this, jsii.String("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
stateJson := map[string]interface{}{
"Type": jsii.String("Task"),
"Resource": jsii.String("arn:aws:states:::dynamodb:putItem"),
"Parameters": map[string]interface{}{
"TableName": table.tableName,
"Item": map[string]map[string]*string{
"id": map[string]*string{
"S": jsii.String("MyEntry"),
},
},
},
"ResultPath": nil,
}
// custom state which represents a task to insert data into DynamoDB
custom := sfn.NewCustomState(this, jsii.String("my custom task"), &CustomStateProps{
StateJson: StateJson,
})
// catch errors with addCatch
errorHandler := sfn.NewPass(this, jsii.String("handle failure"))
custom.AddCatch(errorHandler)
// retry the task if something goes wrong
custom.AddRetry(&RetryProps{
Errors: []*string{
sfn.Errors_ALL(),
},
Interval: awscdk.Duration_Seconds(jsii.Number(10)),
MaxAttempts: jsii.Number(5),
})
chain := sfn.Chain_Start(custom).Next(finalStatus)
sm := sfn.NewStateMachine(this, jsii.String("StateMachine"), &StateMachineProps{
DefinitionBody: sfn.DefinitionBody_FromChainable(chain),
Timeout: awscdk.Duration_*Seconds(jsii.Number(30)),
Comment: jsii.String("a super cool state machine"),
})
// don't forget permissions. You need to assign them
table.GrantWriteData(sm)
Initializer
ts
new Errors()
python
Errors()
java
new Errors()
csharp
new Errors()
go
NewErrors()
Properties
Matches any Error.
BRANCH_FAILEDstringbranch_failedstrBRANCH_FAILEDStringBRANCH_FAILEDstringBRANCH_FAILED*stringrequiredstatic#A branch of a Parallel state failed.
HEARTBEAT_TIMEOUTstringheartbeat_timeoutstrHEARTBEAT_TIMEOUTStringHEARTBEAT_TIMEOUTstringHEARTBEAT_TIMEOUT*stringrequiredstatic#A Task State failed to heartbeat for a time longer than the “HeartbeatSeconds” value.
NO_CHOICE_MATCHEDstringno_choice_matchedstrNO_CHOICE_MATCHEDStringNO_CHOICE_MATCHEDstringNO_CHOICE_MATCHED*stringrequiredstatic#A Choice state failed to find a match for the condition field extracted from its input.
PARAMETER_PATH_FAILUREstringparameter_path_failurestrPARAMETER_PATH_FAILUREStringPARAMETER_PATH_FAILUREstringPARAMETER_PATH_FAILURE*stringrequiredstatic#Within a state’s “Parameters” field, the attempt to replace a field whose name ends in “.$” using a Path failed.
A Task State failed because it had insufficient privileges to execute the specified code.
RESULT_PATH_MATCH_FAILUREstringresult_path_match_failurestrRESULT_PATH_MATCH_FAILUREStringRESULT_PATH_MATCH_FAILUREstringRESULT_PATH_MATCH_FAILURE*stringrequiredstatic#A Task State’s “ResultPath” field cannot be applied to the input the state received.
TASKS_FAILEDstringtasks_failedstrTASKS_FAILEDStringTASKS_FAILEDstringTASKS_FAILED*stringrequiredstatic#A Task State failed during the execution.
A Task State either ran longer than the “TimeoutSeconds” value, or failed to heartbeat for a time longer than the “HeartbeatSeconds” value.