How to pause a Step Function while waiting for a response from a third-party API or other services for up to one year.
Mahmudul Hasan
Software Engineer at PETRONAS | JavaScript, React, Node, Typescript, AWS, Python , Data Structure, Algorithm, Web Performance and Optimization
?
You can pause a Step Function task indefinitely using Task Tokens. This is useful when the task needs to wait for human approval or interact with a third party.
When a task in your state machine is set as a callback task using .waitForTaskToken, a Task Token is generated for that task. This token is placed in the context object of the Step Function when the task starts.
It should be noted that Task Tokens are region and account specific. They are valid up to 1 year, however a new task token will be regenerated automatically if the task state using the callback task token times out.
This action appends .waitForTaskToken to the resource of the state definition in the Step Function's ASL file like this: