0

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)

Hrishikesh
  • 356
  • 2
  • 11
  • There's a type `Wait` that does that: https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-wait-state.html. You can then map the next wait task to the beginning of a task. If you need to exit from it, you can always use Choice. – Jose A Apr 27 '21 at 01:24

2 Answers2

1

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

yucer
  • 4,431
  • 3
  • 34
  • 42
0

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

Hrishikesh
  • 356
  • 2
  • 11