Skip to content

Commit

Permalink
feat: Add support to States.HeartbeatTimeout
Browse files Browse the repository at this point in the history
  • Loading branch information
diegotry committed Aug 17, 2021
1 parent 84a831a commit f099add
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/@aws-cdk/aws-stepfunctions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions packages/@aws-cdk/aws-stepfunctions/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
31 changes: 31 additions & 0 deletions packages/@aws-cdk/aws-stepfunctions/test/task-base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -104,6 +105,36 @@ describe('Task base', () => {
});
});

test('States.HeartbeatTimeout is added correctly', () => {
// 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' });
Expand Down

0 comments on commit f099add

Please sign in to comment.