# service unable to place tasks: reason: task stuck in PENDING state; cannot pull image or resource unavailable

- **ID:** `aws/ecs-task-stuck-in-pending`
- **Domain:** aws
- **Category:** resource_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

ECS task fails to transition from PENDING to RUNNING due to insufficient cluster resources (CPU/memory/ports) or image pull failures.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| ECS 1.30.0 | active | — | — |
| Amazon Linux 2 | active | — | — |
| Docker 20.10.7 | active | — | — |

## Workarounds

1. **Check ECS cluster capacity: run `aws ecs describe-clusters --cluster your-cluster --include ATTACHMENTS` to see running tasks and remaining resources. Scale out by adding EC2 instances or increase max tasks.** (75% success)
   ```
   Check ECS cluster capacity: run `aws ecs describe-clusters --cluster your-cluster --include ATTACHMENTS` to see running tasks and remaining resources. Scale out by adding EC2 instances or increase max tasks.
   ```
2. **Verify image pull: test with `docker pull your-image:tag` on an instance. Ensure ECR repository exists and task execution role has ecr:GetDownloadUrlForLayer and ecr:BatchGetImage permissions.** (85% success)
   ```
   Verify image pull: test with `docker pull your-image:tag` on an instance. Ensure ECR repository exists and task execution role has ecr:GetDownloadUrlForLayer and ecr:BatchGetImage permissions.
   ```
3. **Review task placement constraints: remove or relax constraints like `memberOf` if they're too restrictive. Use `aws ecs describe-tasks --cluster your-cluster --tasks task-id` to get detailed status.** (70% success)
   ```
   Review task placement constraints: remove or relax constraints like `memberOf` if they're too restrictive. Use `aws ecs describe-tasks --cluster your-cluster --tasks task-id` to get detailed status.
   ```

## Dead Ends

- **Increase task definition CPU/memory arbitrarily** — Incorrect resource sizing wastes capacity; actual cause is cluster saturation or image registry issues. (65% fail)
- **Restart the ECS agent on all instances** — Agent restart doesn't free resources or fix image pull problems; only a temporary workaround. (40% fail)
- **Delete and recreate the service** — Service recreation doesn't change underlying resource constraints or image pull failures. (50% fail)
