Fargate 容量不足时该怎么办?

问题描述 投票:0回答:2

我正在使用以下命令启动单个 ECS Fargate 任务:

aws ecs run-task --cluster Fargate \
 --task-definition $ECR_REPO-run-setup 
 --overrides file:///tmp/ecs-overrides-db-migrate.txt \
 --count 1 --launch-type FARGATE \
 --network-configuration "awsvpcConfiguration={subnets=[$PUBLIC_SUBNET_1, $PUBLIC_SUBNET_2],securityGroups=[$FARGATE_SG],assignPubli cIp=ENABLED}"

目前我的账户中根本没有运行任何 ECS 服务、任务或实例。这是我得到的回复:

{
    "failures": [
        {
            "reason": "Capacity is unavailable at this time. Please try again later or in a different availability zone"
        }
    ],
    "tasks": []
}

我什至没有找到为 Fargate 任务指定不同可用区的方法?

如果我应该重试,我应该等待多长时间才能重试?

amazon-ecs aws-fargate
2个回答
11
投票

使用 VPC,您可以创建一个或多个与可用区相对应的子网。

启动 Fargate 任务时,您会注意到

network-configuration
参数和关联的
awsvpcConfiguration
。要指定多个区域,您可以传入多个子网。例如:

aws ecs run-task --cluster Fargate \
 --task-definition $ECR_REPO-run-setup 
 --overrides file:///tmp/ecs-overrides-db-migrate.txt \
 --count 1 --launch-type FARGATE \
 --network-configuration "awsvpcConfiguration={subnets=[$MY_SUBNET_IN_AZ1, 
$MY_SUBNET_IN_AZ2]

aws 中的 VPC 文档包含更多有用的信息: https://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Subnets.html#vpc-subnet-basics


0
投票

我在从已在三个不同可用区 (us-east-1{a,b,c}) 中指定了三个不同子网的 StepFunctions 运行 ECS 任务时遇到此错误。

因为 ECS 文档建议重试此错误 [1],所以我将其视为暂时性的,并使用 StepFunction retry 重试该错误,如下所示:

{

  "States": {

    "Workflow-EcsRunTask-EcsRunTask": {
      "End": true,
      "Retry": [
        {
          "ErrorEquals": [
            "ECS.AmazonECSException" // <-- this is the ECS error type thrown to StepFunction in case of this error
          ],
          "IntervalSeconds": 10,
          "MaxAttempts": 3,
          "BackoffRate": 2
        }
      ],
      "Type": "Task",
      "TimeoutSeconds": 43200,
      "HeartbeatSeconds": 300,
      "Resource": "arn:<REDACTED>"
      ... 

    }

  }

}

[1]: https://docs.aws.amazon.com/AmazonECS/latest/userguide/service-event-messages.html:请参阅服务(服务名称)无法放置任务。原因:此时容量不可用。请稍后或在不同的可用区域重试。

您可以执行以下操作之一:

  • 等待 Fargate 容量或 EC2 容器实例变得可用。
  • 重新启动服务并指定其他子网。
© www.soinside.com 2019 - 2024. All rights reserved.