|
9 | 9 |
|
10 | 10 | *cdk-stepfunctions-patterns* library is a set of [AWS CDK](https://aws.amazon.com/cdk/) constructs that provide |
11 | 11 | resiliency patterns implementation for AWS Step Functions. |
| 12 | + |
| 13 | +## Try / Catch pattern |
| 14 | + |
| 15 | +### Example |
| 16 | +```typescript |
| 17 | +import * as sfn from '@aws-cdk/aws-stepfunctions'; |
| 18 | +import { TryTask } from 'cdk-stepfunctions-patterns'; |
| 19 | + |
| 20 | +// ... |
| 21 | + |
| 22 | +new sfn.StateMachine(this, 'TryCatchStepMachine', { |
| 23 | + definition: new TryTask(this, "TryCatch", { |
| 24 | + tryProcess: new sfn.Pass(this, 'A1').next(new sfn.Pass(this, 'B1')), |
| 25 | + catchProcess: new sfn.Pass(this, 'catchHandler'), |
| 26 | + // optional configuration properties |
| 27 | + catchProps: { |
| 28 | + errors: ['Lambda.AWSLambdaException'], |
| 29 | + resultPath: "$.ErrorDetails" |
| 30 | + } |
| 31 | + }) |
| 32 | +}) |
| 33 | +``` |
| 34 | + |
| 35 | +### Resulting StepFunction |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | +## Try / Finally pattern |
| 40 | + |
| 41 | +### Example |
| 42 | + |
| 43 | +```typescript |
| 44 | +import * as sfn from '@aws-cdk/aws-stepfunctions'; |
| 45 | +import { TryTask } from 'cdk-stepfunctions-patterns'; |
| 46 | + |
| 47 | +// ... |
| 48 | + |
| 49 | +new sfn.StateMachine(this, 'TryFinallyStepMachine', { |
| 50 | + definition: new TryTask(this, "TryFinally", { |
| 51 | + tryProcess: new sfn.Pass(this, 'A2').next(new sfn.Pass(this, 'B2')), |
| 52 | + finallyProcess: new sfn.Pass(this, 'finallyHandler'), |
| 53 | + // optional configuration properties |
| 54 | + catchErrorPath: "$.FinallyErrorDetails" |
| 55 | + }) |
| 56 | +}) |
| 57 | +``` |
| 58 | + |
| 59 | +### Resulting StepFunction |
| 60 | + |
| 61 | + |
| 62 | +## Try / Catch / Finally pattern |
| 63 | + |
| 64 | +### Example |
| 65 | +```typescript |
| 66 | +import * as sfn from '@aws-cdk/aws-stepfunctions'; |
| 67 | +import { TryTask } from 'cdk-stepfunctions-patterns'; |
| 68 | + |
| 69 | +// ... |
| 70 | + |
| 71 | +new sfn.StateMachine(this, 'TryCatchFinallyStepMachine', { |
| 72 | + definition: new TryTask(this, "TryCatchFinalli", { |
| 73 | + tryProcess: new sfn.Pass(this, 'A3').next(new sfn.Pass(this, 'B3')), |
| 74 | + catchProcess: new sfn.Pass(this, 'catchHandler3'), |
| 75 | + finallyProcess: new sfn.Pass(this, 'finallyHandler3') |
| 76 | + }) |
| 77 | +}) |
| 78 | +``` |
| 79 | + |
| 80 | +### Resulting StepFunction |
| 81 | + |
| 82 | + |
| 83 | +## Retry with backoff and jitter |
| 84 | + |
| 85 | +### Example |
| 86 | +```typescript |
| 87 | +import * as sfn from '@aws-cdk/aws-stepfunctions'; |
| 88 | +import { RetryWithJitterTask } from 'cdk-stepfunctions-patterns'; |
| 89 | + |
| 90 | +// ... |
| 91 | + |
| 92 | +new sfn.StateMachine(this, 'RetryWithJitterStepMachine', { |
| 93 | + definition: new RetryWithJitterTask(this, "AWithJitter", { |
| 94 | + tryProcess: new sfn.Pass(this, 'A4').next(new sfn.Pass(this, 'B4')), |
| 95 | + retryProps: { errors: ["States.ALL"], maxAttempts: 3 } |
| 96 | + }) |
| 97 | +}) |
| 98 | +``` |
| 99 | + |
| 100 | +### Resulting StepFunction |
| 101 | + |
0 commit comments