Im developer who is new to AWS.
While configuring step functions, I found there are some senarious that there could be multiple step functions instance executed because of timer I've set.
for the step function that I configured follows below process
- wait 2 minute
- execute lambda function
since there is timer in my step function, there could be some cases that, step function might invoked multiple times at a time.
the thing is that, I wan't to guarantee that on execution queue, only one step function in on.
so if any other step function gets invoked, while step function in on running(timing), I wan't to terminate step function that just got invoked. is there any way to list step functions that are executing?
CodePudding user response:
You can't prevent an execution from starting, but you can list the executions at the start of your Step Function, and exit early if a running execution is found.
The ListExecutions API lists the executions for a given state machine ARN. Call it in a Task, setting the statusFilter
to RUNNING
to return only in-progress executions. You'll get back a list of matching execution items. All you care about is whether the length > 0.
Finally, insert a Choice state. If there are running items, exit. If no running items, continue with the execution.