Stepfunction 超时不会停止 Fargate 任务

Stepfunction timeout does not stop Fargate task

我有一个 step 函数,可以协调 lambda 和 fargate 任务的组合。此步骤函数的超时设置为 24 小时。但是,此超时不会传播到取消已经 运行 fargate 任务。

我之前查看过 以将成功和失败消息发送回 step 函数,效果很好。不过我不知道如何解决超时问题。

当前配置如下所示:

    {
    "StartAt": "Fargate-task",
    "States": {
    "Fargate-task": {
        "Next": "pass-state",
        "Catch": [
        {
            "ErrorEquals": [
            "States.ALL"
            ],
            "Next": "fail-state"
        }
        ],
        "Type": "Task",
        "TimeoutSeconds": 60,
        "ResultPath": "$.extractor_output",
        "Resource": "arn:aws:states:::ecs:runTask.waitForTaskToken"
    },
    "pass-state": {
        "Type": "Pass",
        "Next": "Lambda Worker"
    },
    "Lambda Worker": {
        "Type": "Map",
        "End": true,
        "Iterator": {
        "StartAt": "LambdaWorker",
        "States": {
            "LambdaWorker": {
            "End": true,
            "Retry": [
                {
                "ErrorEquals": [
                    "Lambda.ServiceException",
                    "Lambda.AWSLambdaException",
                    "Lambda.SdkClientException"
                ],
                "IntervalSeconds": 2,
                "MaxAttempts": 6,
                "BackoffRate": 2
                }
            ],
            "Type": "Task",
            "Resource": "arn:aws:states:::lambda:invoke",
            "Parameters": {
                "FunctionName": "<LAMBDA>",
                "Payload.$": "$"
            }
            }
        }
        },
        "ItemsPath": "$.extractor_output",
        "MaxConcurrency": 10
    },
    "fail-state": {
        "Type": "Fail"
    }
    }
}

处理它的一种方法是捕获超时错误并发出命令以终止 fargate 任务:

就像文档中的这个例子 https://docs.aws.amazon.com/step-functions/latest/dg/concepts-error-handling.html :

{
   "Comment": "A Hello World example of the Amazon States Language using an AWS Lambda function",
   "StartAt": "HelloWorld",
   "States": {
      "HelloWorld": {
         "Type": "Task",
         "Resource": "arn:aws:lambda:us-east-1:123456789012:function:sleep10",
         "TimeoutSeconds": 2,
         "Catch": [ {
            "ErrorEquals": ["States.Timeout"],
            "Next": "fallback"
         } ],
         "End": true
      },
      "fallback": {
         "Type": "Pass",
         "Result": "Hello, AWS Step Functions!",
         "End": true
      }
   }
}