You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*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
12
13
+
All these patterns are *composable*, meaning that you can combine them together to create
14
+
quite complex state machines that are much easier to maintain and support than low-level
15
+
JSON definitions.
16
+
13
17
## Try / Catch pattern
18
+
Step Functions support **Try / Catch** pattern natively with [Task](https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-task-state.html)
19
+
and [Parallel](https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-parallel-state.html) states.
20
+
21
+
`TryTask` construct adds a high level abstraction that allows you to use Try / Catch pattern with any state or sequence of states.
14
22
15
23
### Example
16
24
```typescript
@@ -37,6 +45,15 @@ new sfn.StateMachine(this, 'TryCatchStepMachine', {
37
45
38
46
39
47
## Try / Finally pattern
48
+
It is often useful to design state machine using **Try / Finally** pattern. The idea is to have a *Final* state that has to be
49
+
executed regardless of successful or failed execution of the *Try* state. There may be some temporal resource you want
50
+
to delete or notification to send.
51
+
52
+
Step Functions do not provide a native way to implement that pattern but it can be done using
53
+
[Parallel](https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-parallel-state.html) state and *catch all* catch
54
+
specification.
55
+
56
+
`TryTask` construct abstracts these implementation details and allows to express the pattern directly.
40
57
41
58
### Example
42
59
@@ -48,10 +65,10 @@ import { TryTask } from 'cdk-stepfunctions-patterns';
@@ -81,6 +100,14 @@ new sfn.StateMachine(this, 'TryCatchFinallyStepMachine', {
81
100

82
101
83
102
## Retry with backoff and jitter
103
+
Out of the box Step Functions retry implementation provides a way to configure backoff factor,
104
+
but there is no built in way to introduce jitter. As covered in
105
+
[Exponential Backoff And Jitter](https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/)
106
+
and [Wait and Retry with Jittered Back-off](https://github.com/Polly-Contrib/Polly.Contrib.WaitAndRetry#wait-and-retry-with-jittered-back-off) this retry technique can be very helpful in high-load
107
+
scenarios.
108
+
109
+
`RetryWithJitterTask` construct provides a custom implementation of retry with backoff and
110
+
jitter that you can use directly in your state machines.
84
111
85
112
### Example
86
113
```typescript
@@ -91,11 +118,92 @@ import { RetryWithJitterTask } from 'cdk-stepfunctions-patterns';
0 commit comments