From 99f27db6fb8f1c12bce7e194e12eae681fe03e58 Mon Sep 17 00:00:00 2001 From: Diego Santiviago Date: Sat, 14 Aug 2021 23:43:18 -0700 Subject: [PATCH] feat: Add support to States.HeartbeatTimeout --- packages/@aws-cdk/aws-stepfunctions/README.md | 15 +++++++++ .../@aws-cdk/aws-stepfunctions/lib/types.ts | 5 +++ .../aws-stepfunctions/test/task-base.test.ts | 31 +++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/packages/@aws-cdk/aws-stepfunctions/README.md b/packages/@aws-cdk/aws-stepfunctions/README.md index f22d45f9f475d..53f7478a8cf48 100644 --- a/packages/@aws-cdk/aws-stepfunctions/README.md +++ b/packages/@aws-cdk/aws-stepfunctions/README.md @@ -555,6 +555,21 @@ new cloudwatch.Alarm(this, 'ThrottledAlarm', { }); ``` +## Error names + +Step Functions identifies errors in the Amazon States Language using case-sensitive strings, known as error names. +The Amazon States Language defines a set of built-in strings that name well-known errors, all beginning with the States. prefix. + +* `States.ALL` - A wildcard that matches any known error name. +* `States.Runtime` - An execution failed due to some exception that could not be processed. Often these are caused by errors at runtime, such as attempting to apply InputPath or OutputPath on a null JSON payload. A `States.Runtime` error is not retriable, and will always cause the execution to fail. A retry or catch on `States.ALL` will NOT catch States.Runtime errors. +* `States.DataLimitExceeded` - A States.DataLimitExceeded exception will be thrown for the following: + * When the output of a connector is larger than payload size quota. + * When the output of a state is larger than payload size quota. + * When, after Parameters processing, the input of a state is larger than the payload size quota. +* `States.HeartbeatTimeout` - A Task state failed to send a heartbeat for a period longer than the HeartbeatSeconds value. +* `States.Timeout` - A Task state either ran longer than the TimeoutSeconds value, or failed to send a heartbeat for a period longer than the HeartbeatSeconds value. +* `States.TaskFailed`- A Task state failed during the execution. When used in a retry or catch, `States.TaskFailed` acts as a wildcard that matches any known error name except for `States.Timeout`. + ## Logging Enable logging to CloudWatch by passing a logging configuration with a diff --git a/packages/@aws-cdk/aws-stepfunctions/lib/types.ts b/packages/@aws-cdk/aws-stepfunctions/lib/types.ts index a376ace3b24ea..5a263d59be1e8 100644 --- a/packages/@aws-cdk/aws-stepfunctions/lib/types.ts +++ b/packages/@aws-cdk/aws-stepfunctions/lib/types.ts @@ -45,6 +45,11 @@ export class Errors { */ public static readonly ALL = 'States.ALL'; + /** + * A Task State failed to heartbeat for a time longer than the “HeartbeatSeconds” value. + */ + public static readonly HEARTBEAT_TIMEOUT_ERROR = 'States.HeartbeatTimeout'; + /** * A Task State either ran longer than the “TimeoutSeconds” value, or * failed to heartbeat for a time longer than the “HeartbeatSeconds” value. diff --git a/packages/@aws-cdk/aws-stepfunctions/test/task-base.test.ts b/packages/@aws-cdk/aws-stepfunctions/test/task-base.test.ts index a57c489134efd..c6a2859bacd20 100644 --- a/packages/@aws-cdk/aws-stepfunctions/test/task-base.test.ts +++ b/packages/@aws-cdk/aws-stepfunctions/test/task-base.test.ts @@ -4,6 +4,7 @@ import * as iam from '@aws-cdk/aws-iam'; import * as cdk from '@aws-cdk/core'; import * as constructs from 'constructs'; import * as sfn from '../lib'; +import { Errors } from '../lib'; describe('Task base', () => { let stack: cdk.Stack; @@ -104,6 +105,36 @@ describe('Task base', () => { }); }); + test('States.HeartbeatTimeout is added correctky', () => { + // GIVEN + const heartbeatFailState = new sfn.Fail(stack, 'HeartbeatFailState'); + + // WHEN + task.addCatch(heartbeatFailState, { errors: [Errors.HEARTBEAT_TIMEOUT_ERROR] }); + + // THEN + expect(render(task)).toEqual({ + StartAt: 'my-task', + States: { + 'HeartbeatFailState': { + Type: 'Fail', + }, + 'my-task': { + End: true, + Catch: [ + { + ErrorEquals: ['States.HeartbeatTimeout'], + Next: 'HeartbeatFailState', + }, + ], + Type: 'Task', + Resource: 'my-resource', + Parameters: { MyParameter: 'myParameter' }, + }, + }, + }); + }); + test('States.ALL catch appears at end of list', () => { // GIVEN const httpFailure = new sfn.Fail(stack, 'http', { error: 'HTTP' });