【问题标题】:How to stop all running Step Functions of a specific state machine?如何停止特定状态机的所有正在运行的 Step Functions?
【发布时间】:2022-04-19 22:38:10
【问题描述】:

我不小心启动了很多步进函数,现在希望终止所有这些函数。

使用 CLI 或 Web 控制台执行此操作的任何智能方法?

【问题讨论】:

    标签: aws-cli aws-step-functions


    【解决方案1】:

    好的,让我们使用 CLI 执行此操作。

    您可以使用以下命令停止执行:

    aws stepfunctions stop-execution \
      --execution-arn <STEP FUNCTION EXECUTION ARN>
    

    但由于我开始执行的执行次数过多,因此能够列出状态机的所有正在运行的执行情况会很有帮助:

    aws stepfunctions list-executions \
      --state-machine-arn <STEP FUNCTION ARN> \
      --status-filter RUNNING \
      --output text
    

    接下来,确保仅列出这些执行的执行 ARN,并在单独的行上列出每个执行 ARN:

    aws stepfunctions list-executions \
      --state-machine-arn <STEP FUNCTION ARN> \
      --status-filter RUNNING \
      --query "executions[*].{executionArn:executionArn}" \
      --output text
    

    现在,我们使用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 {} 
    

    现在应该关闭所有正在运行的执行。请务必小心操作,以免搞砸生产!

    关于这一点,如果您使用 aws-vault 来最大程度地降低这种风险,那么上面的命令将如下所示:

    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 {} 
    

    【讨论】:

    • 好的,这太棒了,感谢一步一步的解释
    【解决方案2】:

    对我来说,xargs 是个问题,因为我的 execution-arn 足够大。

    aws stepfunctions list-executions \
      --state-machine-arn <ARN> \
      --status-filter RUNNING \
      --query "executions[*].{executionArn:executionArn}" \
      --output text | \
        awk '{print}' |
        while read line;
        do aws stepfunctions stop-execution --execution-arn  $line
        done
    

    这对我有用。感谢@Pål Brattberg

    【讨论】:

      【解决方案3】:

      由于某种原因,每次迭代后,它都会卡在 Mac 中,

      添加 &gt;&gt; out.t 即可解决

      aws stepfunctions list-executions \
      --state-machine-arn arn:aws:states:us-east-1:322348515048:stateMachine:workflow-dev-acknowledge-Awaiter \
      --status-filter RUNNING \
      --query "executions[*].{executionArn:executionArn}" \
      --output text | \
      xargs -I {} aws stepfunctions stop-execution \
      --execution-arn {} >> out.t
      

      【讨论】:

      • 奇怪!你用的是什么版本的mac和什么shell?
      猜你喜欢
      • 1970-01-01
      • 2018-09-14
      • 1970-01-01
      • 2022-09-23
      • 2021-06-06
      • 1970-01-01
      • 2022-10-13
      • 2021-08-02
      • 2020-09-05
      相关资源
      最近更新 更多