Introduction
ECS Fargate has specific CPU-memory combinations that are valid. When you configure a task definition with an unsupported combination, tasks fail to launch. Fargate doesn't allow arbitrary CPU and memory values - they must match predefined configurations.
Symptoms
Task creation fails:
```bash $ aws ecs run-task --task-definition my-task --launch-type FARGATE
An error occurred (InvalidParameterException) when calling the RunTask operation: Task definition does not support Fargate launch type. The CPU and memory configuration is invalid. ```
Task stuck in PENDING then fails:
```bash $ aws ecs describe-tasks --cluster my-cluster --tasks abc123
"lastStatus": "STOPPED", "stoppedReason": "Task failed to start: Invalid CPU and memory configuration" ```
Console error:
Fargate task CPU and memory values must be from the allowed set of values.Common Causes
- 1.Invalid CPU-memory combination - Values don't match Fargate's predefined options
- 2.Memory too high for CPU - Memory exceeds limit for selected CPU level
- 3.CPU not Fargate-compatible - Using EC2-only CPU values
- 4.Task definition error - CPU/memory specified as strings with wrong units
- 5.Ephemeral storage mismatch - For CPU-memory configs that require specific storage
Step-by-Step Fix
- 1.Check logs for specific error messages
- 2.Verify configuration settings
- 3.Test network connectivity
- 4.Review recent changes
- 5.Apply corrective action
- 6.Verify the fix
Step 1: Check Fargate Valid CPU Values
Fargate supports specific CPU values:
| CPU Value | Memory Range |
|---|---|
| 256 (.25 vCPU) | 512 MB - 2 GB |
| 512 (.5 vCPU) | 1 GB - 4 GB |
| 1024 (1 vCPU) | 2 GB - 8 GB |
| 2048 (2 vCPU) | 4 GB - 16 GB |
| 4096 (4 vCPU) | 8 GB - 30 GB |
# Check current task definition
aws ecs describe-task-definition --task-definition my-task:1 \
--query 'taskDefinition.[cpu,memory]'Step 2: Verify Memory Values
Memory must be in the valid range for your CPU:
```bash # List memory options for 512 CPU (.5 vCPU) # Valid: 1024, 2048, 3072, 4096 (1-4 GB in 1 GB increments)
# For 1024 CPU (1 vCPU) # Valid: 2048, 3072, 4096, 5120, 6144, 7168, 8192 (2-8 GB)
# For 2048 CPU (2 vCPU) # Valid: 4096-16384 in 1 GB increments (4-16 GB)
# For 4096 CPU (4 vCPU) # Valid: 8192-30720 in 1 GB increments (8-30 GB) ```
Step 3: Check Task Definition Configuration
```bash # Get task definition CPU and memory aws ecs describe-task-definition --task-definition my-task:1 \ --query 'taskDefinition.{CPU:cpu,Memory:memory,EphemeralStorage:ephemeralStorage}'
# CPU should be integer string: "256", "512", "1024", "2048", "4096" # Memory should be integer string in MB: "1024", "2048", etc. ```
Common errors: - Using "0.5 vCPU" instead of "512" - Using "2GB" instead of "2048" - Memory outside allowed range for CPU
Step 4: Fix Invalid CPU-Memory Combination
```bash # Register new task definition with valid values aws ecs register-task-definition \ --family my-task \ --cpu "512" \ --memory "2048" \ --network-mode awsvpc \ --requires-compatibilities FARGATE \ --container-definitions '[ { "name": "my-container", "image": "nginx", "essential": true, "memoryReservation": 1024 } ]'
# Update service with new task definition aws ecs update-service --cluster my-cluster --service my-service \ --task-definition my-task:2 ```
Step 5: Validate Memory Reservation vs Memory Limit
Container memory settings must be <= task memory:
```bash # Check container definitions aws ecs describe-task-definition --task-definition my-task:1 \ --query 'taskDefinition.containerDefinitions[*].[name,memory,memoryReservation]'
# memory: hard limit (container killed if exceeded) # memoryReservation: soft limit (reservation guarantee)
# Container memory limit must not exceed task memory # If task has 2048 MB, container memory should be <= 2048 ```
Fix container memory:
# Update task definition with correct container memory
aws ecs register-task-definition \
--family my-task \
--cpu "1024" \
--memory "4096" \
--container-definitions '[
{
"name": "app",
"image": "myimage",
"memory": 2048,
"memoryReservation": 1024
}
]' \
--requires-compatibilities FARGATE \
--network-mode awsvpcStep 6: Check Ephemeral Storage Requirements
For Fargate tasks with CPU >= 4096 (4 vCPU):
```bash # Higher CPU-memory configs may need ephemeral storage # Default: 20 GB # Available: 20 GB - 200 GB (for tasks launched after May 2024)
# Add ephemeral storage configuration aws ecs register-task-definition \ --family my-task \ --cpu "4096" \ --memory "16384" \ --ephemeral-storage '{"sizeInGiB": 50}' \ --requires-compatibilities FARGATE \ --network-mode awsvpc \ --container-definitions '...' ```
Step 7: Calculate Required CPU-Memory
```bash # Estimate based on container needs # Sum all container memory reservations # Add overhead (typically 10-20%)
# Example: 3 containers # Container 1: 1 GB # Container 2: 512 MB # Container 3: 256 MB # Total: 1792 MB + 20% overhead = ~2150 MB
# Valid options with 2150 MB needed: # CPU 1024 (1 vCPU) with Memory 2048 or 3072 # Choose memory 3072 (3 GB) for safety margin ```
Step 8: Compare EC2 vs Fargate Configurations
```bash # EC2 launch type allows flexible CPU/memory # Fargate requires specific combinations
# If task works on EC2 but fails on Fargate: aws ecs describe-task-definition --task-definition my-task:1 \ --query 'taskDefinition.requiresCompatibilities'
# If empty or only EC2, need Fargate-compatible config ```
Step 9: Check Service Quotas
```bash # Check Fargate resource quotas aws service-quotas get-service-quota \ --service-code fargate \ --quota-code L-3032A538 # Fargate On-Demand resource count
# Request increase if hitting limits aws service-quotas request-service-quota-increase \ --service-code fargate \ --quota-code L-3032A538 \ --desired-value 100 ```
Step 10: Validate with Test Task
```bash # Run test task with corrected configuration aws ecs run-task \ --cluster my-cluster \ --task-definition my-task:NEW_VERSION \ --launch-type FARGATE \ --network-configuration 'awsvpcConfiguration={subnets=[subnet-12345],securityGroups=[sg-12345],assignPublicIp=ENABLED}'
# Monitor task status aws ecs describe-tasks --cluster my-cluster --tasks TASK_ID \ --query 'tasks[*].[lastStatus,stoppedReason]' ```
Fargate CPU-Memory Quick Reference
Valid combinations:
| CPU (vCPU) | Memory (GB) | Task Example Use |
|---|---|---|
| 256 (.25) | 0.5-2 | Micro services, sidecars |
| 512 (.5) | 1-4 | Small web apps |
| 1024 (1) | 2-8 | Standard web apps |
| 2048 (2) | 4-16 | Medium workloads |
| 4096 (4) | 8-30 | Large workloads, ML |
Verification
```bash # Run task and verify it starts aws ecs run-task --cluster my-cluster --task-definition my-task:NEW --launch-type FARGATE
# Task should go from PENDING to RUNNING aws ecs describe-tasks --cluster my-cluster --tasks TASK_ID \ --query 'tasks[*].[lastStatus,containers[*].lastStatus]'
# Should show: RUNNING, RUNNING ```
Related Issues
- [Fix AWS ECS Task Stuck in Pending](/articles/fix-aws-ecs-task-pending)
- [Fix AWS ECS Service Unstable](/articles/fix-aws-ecs-service-unstable)
- [Fix AWS ECS Exec Command Not Working](/articles/fix-aws-ecs-exec-command-not-working)
Related Articles
- [AWS troubleshooting: Fix IAM Permission Denied - Complete Tro](fix-iam-permission-denied)
- [AWS cloud troubleshooting: AWS ACM Certificate Pending Validation Because the](aws-acm-certificate-pending-validation-wrong-route53-zone)
- [AWS cloud troubleshooting: AWS ALB Returns 502 Because the Target Closed the ](aws-alb-502-target-closed-connection-keepalive-timeout-mismatch)
- [AWS cloud troubleshooting: Fix AWS ALB CreateListener TargetGroupNotFound Err](aws-alb-createlistener-targetgroupnotfound)
- [AWS cloud troubleshooting: Fix Aws Alb Lambda 502 Bad Gateway Issue in AWS](aws-alb-lambda-502-bad-gateway)
<script type="application/ld+json"> { "@context": "https://schema.org", "@type": "TechArticle", "headline": "Fix AWS ECS Fargate CPU Memory Configuration Error", "description": "Troubleshoot ECS Fargate CPU and memory configuration errors. Fix invalid combinations, adjust task definitions, and understand valid configurations.", "url": "https://www.fixwikihub.com/fix-aws-ecs-fargate-cpu-memory-wrong", "publisher": { "@type": "Organization", "name": "FixWikiHub", "url": "https://www.fixwikihub.com" }, "author": { "@type": "Person", "name": "FixWikiHub Editorial Team" }, "datePublished": "2026-04-01T14:50:49.721Z", "dateModified": "2026-04-01T14:50:49.721Z" } </script>