class Errors
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.StepFunctions.Errors |
Go | github.com/aws/aws-cdk-go/awscdk/v2/awsstepfunctions#Errors |
Java | software.amazon.awscdk.services.stepfunctions.Errors |
Python | aws_cdk.aws_stepfunctions.Errors |
TypeScript (source) | aws-cdk-lib » aws_stepfunctions » Errors |
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
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 Errors()
Properties
Name | Type | Description |
---|---|---|
static ALL | string | Matches any Error. |
static BRANCH_FAILED | string | A branch of a Parallel state failed. |
static HEARTBEAT_TIMEOUT | string | A Task State failed to heartbeat for a time longer than the “HeartbeatSeconds” value. |
static NO_CHOICE_MATCHED | string | A Choice state failed to find a match for the condition field extracted from its input. |
static PARAMETER_PATH_FAILURE | string | Within a state’s “Parameters” field, the attempt to replace a field whose name ends in “.$” using a Path failed. |
static PERMISSIONS | string | A Task State failed because it had insufficient privileges to execute the specified code. |
static RESULT_PATH_MATCH_FAILURE | string | A Task State’s “ResultPath” field cannot be applied to the input the state received. |
static TASKS_FAILED | string | A Task State failed during the execution. |
static TIMEOUT | string | A Task State either ran longer than the “TimeoutSeconds” value, or failed to heartbeat for a time longer than the “HeartbeatSeconds” value. |
static ALL
Type:
string
Matches any Error.
static BRANCH_FAILED
Type:
string
A branch of a Parallel state failed.
static HEARTBEAT_TIMEOUT
Type:
string
A Task State failed to heartbeat for a time longer than the “HeartbeatSeconds” value.
static NO_CHOICE_MATCHED
Type:
string
A Choice state failed to find a match for the condition field extracted from its input.
static PARAMETER_PATH_FAILURE
Type:
string
Within a state’s “Parameters” field, the attempt to replace a field whose name ends in “.$” using a Path failed.
static PERMISSIONS
Type:
string
A Task State failed because it had insufficient privileges to execute the specified code.
static RESULT_PATH_MATCH_FAILURE
Type:
string
A Task State’s “ResultPath” field cannot be applied to the input the state received.
static TASKS_FAILED
Type:
string
A Task State failed during the execution.
static TIMEOUT
Type:
string
A Task State either ran longer than the “TimeoutSeconds” value, or failed to heartbeat for a time longer than the “HeartbeatSeconds” value.