How to stop all running Step Functions of a specific state machine?

青春壹個敷衍的年華 提交于 2021-01-29 07:09:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!