问题
I accidentally started very many step functions and now wish to terminate all of them.
Any smart ways to do this using the CLI or web console?
回答1:
OK, let's do this using the CLI.
You can stop an execution using the following:
aws stepfunctions stop-execution \
--execution-arn <STEP FUNCTION EXECUTION ARN>
But since I started way too many executions, it's helpful to be able to list all running executions of a state machine:
aws stepfunctions list-executions \
--state-machine-arn <STEP FUNCTION ARN> \
--status-filter RUNNING \
--output text
Next, make sure to only list execution ARN's for these executions and list each execution ARN on a separate line:
aws stepfunctions list-executions \
--state-machine-arn <STEP FUNCTION ARN> \
--status-filter RUNNING \
--query "executions[*].{executionArn:executionArn}" \
--output text
Now, we put this together into one command using xargs
:
aws stepfunctions list-executions \
--state-machine-arn <STEP FUNCTION ARN> \
--status-filter RUNNING \
--query "executions[*].{executionArn:executionArn}" \
--output text | \
xargs -I {} aws stepfunctions stop-execution \
--execution-arn {}
Now all running executions should be shut down. Make sure you do this with care so that you don't mess up production!
On that note, if you user aws-vault to minimize that very risk, the command above would look something like this:
aws-vault exec test-env -- aws stepfunctions list-executions \
--state-machine-arn <STEP FUNCTION ARN> \
--status-filter RUNNING \
--query "executions[*].{executionArn:executionArn}" \
--output text | \
xargs -I {} aws-vault exec test-env -- aws stepfunctions stop-execution \
--execution-arn {}
来源:https://stackoverflow.com/questions/64845076/how-to-stop-all-running-step-functions-of-a-specific-state-machine