# 服务无法放置任务：原因：此时容量不可用。

- **ID:** `aws/ecs-task-stuck-pending-capacity`
- **领域:** aws
- **类别:** resource_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

ECS 集群缺乏足够的 EC2 或 Fargate 容量来启动任务，通常由于可用区中的实例类型不可用。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| ecs-2024-06 | active | — | — |
| fargate-1.4.0 | active | — | — |
| ecs-cli-2.0.0 | active | — | — |

## 解决方案

1. ```
   更改任务放置策略以跨多个可用区分布：`aws ecs update-service --cluster my-cluster --service my-service --placement-strategy type=spread,field=attribute:ecs.availability-zone`
   ```
2. ```
   使用不同的实例类型或 Fargate 平台版本：更新任务定义以使用 `FARGATE` 或不同的 CPU/内存组合。
   ```

## 无效尝试

- **** — Restarting the ECS service doesn't free capacity; the underlying resource shortage persists. (90% 失败率)
- **** — Increasing task count makes the problem worse by requesting more unavailable capacity. (80% 失败率)
