To start at most one instance of a workflow with a given ID — as in, prevent launching more than one workflow at a time, you’d want to set a workflow ID. From the docs:
It is not possible for a new Workflow Execution to spawn with the same Workflow Id as another Open Workflow Execution, regardless of the Workflow Id Reuse Policy.
An attempt to start a workflow with an ID will fail. This can be adjust via the workflow ID conflict policy which determines what should be done when attempting to start a workflow with the same ID. The valid options are:
- Fail: return an error. This is the default.
- Use existing: prevent the workflow from spawning but return the currently running workflow as the Start response.
- Terminate existing: terminate the existing workflow, spawn a new one with the same workflow ID, and return that as the Start response.
There also exists a workflow ID reuse policy which dictates what should happen when starting a workflow with the same ID of a closed workflow. Valid options are:
- Allow duplicates: allow starting a new workflow with a duplicate ID. This is the default.
- Allow duplicates failed only: allow starting a new workflow with a duplicate ID only if there exists one in the failed state (terminated, cancelled, time-out, failed)
- Reject duplicates: do not allow duplicate workflow IDs at all.
Thus, the approach for having exactly one instance of a running workflow is to set a workflow ID. The defaults will do the rest.