Reputation:
I want to limit the number of executions of my step functions to 1 at any given time. Is there a way to put a global lock on AWS Step functions?
Upvotes: 3
Views: 6839
Reputation: 81
Hello I have solved it in the Step-Function by displaying all StepFunction in the Running-State. It will then compare the last entry of the list with the current execution name, if it fits together it runs the normal part, if it deviates it waited 30sec and checked again whether it fits together.
{
"StartAt": "ListExecutions",
"States": {
"ListExecutions": {
"Type": "Task",
"Parameters": {
"StateMachineArn": "arn:aws:states:region:account-id:stateMachine:MyStateMachine",
"StatusFilter": "RUNNING"
},
"Resource": "arn:aws:states:::aws-sdk:sfn:listExecutions",
"Next": "Choice",
"OutputPath": "$.Executions[-1:]"
},
"Choice": {
"Type": "Choice",
"Choices": [
{
"And": [
{
"Variable": "$[0].Name",
"StringEqualsPath": "$$.Execution.Name"
}
],
"Next": "dummy processing"
}
],
"Default": "waiting for completion"
},
"dummy processing": {
"Type": "Wait",
"Seconds": 15,
"End": true
},
"waiting for completion": {
"Type": "Wait",
"Seconds": 30,
"Next": "ListExecutions"
}
}
}
Upvotes: 8
Reputation: 19758
You can achieve this by putting the lock on the function/service which triggers the step function.
For example, if you trigger the step function from a Lambda (External to the step function), you can put the lock in the invoking Lambda function. To implement the lock, you might need an external storage to keep execution state.
Upvotes: 2