将 AWS Step Functions 限制为一次只能运行一个执行



我想在任何给定时间将我的步进函数的执行次数限制为 1。有没有办法对 AWS Step 函数进行全局锁定?

您好,我已经通过在运行状态下显示所有步骤函数在步进函数中解决了它。然后,它将列表的最后一个条目与当前执行名称进行比较,如果它适合在一起,则运行正常部分,如果它偏离,则等待 30 秒并再次检查它是否适合在一起。

步进功能

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

您可以通过锁定触发步骤函数的函数/服务来实现此目的。

例如,如果您从 Lambda(步骤函数外部(触发步骤函数,则可以将锁放入调用 Lambda 函数中。若要实现锁定,可能需要外部存储来保持执行状态。

最新更新