Exponential Wait time in AWS Step Function

2.4k Views Asked by At

Currently, a wait state in AWS can wait only for a defined set period of time.

let's say my step function checks with API for status if the status is updated it will move ahead or else it will wait again for a set period of time!

I would like to make this waiting period dynamic

i.e. (the backoff rate is set to 2)

1st retry: wait for 3600s

2nd retry: wait for 7200s (3600x2)

3rd retry: wait for 14400s (7200x2)

and so on.

Is there any way I can do this without using any other external computation resource (such as lambda)

2

There are 2 best solutions below

0
On

Just raise a custom exception (for example: StatusNotUpdated) in your function if the status is not updated, and then you can define the step like this:

"Check API Status": {
   "Type": "Task",
   "Resource": "arn:aws:states:us-east-1:123456789012:task:check_api_status",
   "Next": "Status Updated",
   "Retry": [ {
      "ErrorEquals": [ "StatusNotUpdated" ],
      "IntervalSeconds": 3600,
      "BackoffRate": 2.0,
      "MaxAttempts": 15
   } ],
   "Catch": [ {
      "ErrorEquals": [ "States.ALL" ],
      "Next": "Status Update Failed"
   } ]
}

Check here for more info

0
On

I was not able to find a inbuilt tool for this So I created a custom logic in a library

the library has 2 parts

  • CDK template housing the lambda/compute service
  • Service Code housing the exp wait logic code

The approach I took to solve this problem was when the request comes in the step function I append an object with wait time parameters

These parameters are used by the lambda to calculate the dynamic wait time and update the json path with new wait time value