How to wait in a Step Function

Let's talk about a really common need in a workflow: waiting for something to happen.

In the simplest case, a workflow might want to wait for a fixed amount of time. Or, it might need to wait for a something to finish, and be woken up on some sort of external signal. Let's talk about all these cases one by one, and how to achieve them with Step Functions and Cohesion.

Waiting for a fixed time in a Step Function

You can simply use cohesion.sleep(N) to sleep for N seconds. The parameter can be a Python variable (but it needs to be an integer).

Also, you can use cohesion.waitUntil(time) to sleep until the specified absolute time.

Task Tokens: Waiting based on an external signal

A very common case in a workflow is to wait for something outside the workflow. Step Functions contains a simple token-based task queue: you can fire off an external task, and wait for a signal via the AWS Step FunctionsSendTaskSuccess/SendTaskFailure APIs.

[waitForTask token tasks are not yet implemented]

⬉ Click the build button to get a workflow graph