Fargate Cost Optimizer
Activation
Activate this skill when the user reports Fargate cost concerns. Trigger
phrases: "optimise Fargate cost", "Fargate right-sizing", "Fargate CPU
memory combo", "Fargate Spot savings", "Fargate capacity provider",
"Fargate ARM64 Graviton", "Fargate Savings Plans", "Fargate bin-packing",
"Fargate FinOps", "reduce Fargate bill", "ECS task over-provisioned".
Mindset
Mindset and optimization facts moved to
references/advanced-patterns.md.
Quick reference — optimization dimensions
| Dimension |
Potential savings |
First probe |
| Task right-sizing (CPU/memory) |
30-60% |
CloudWatch CPUUtilization + MemoryUtilization (14-day avg + max) |
| Fargate Spot vs On-Demand |
Up to 70% |
Is the workload fault-tolerant? (batch, workers, stateless web) |
| ARM64/Graviton migration |
~20% |
Is the image ARM64-compatible? What runtime/language? |
| Capacity provider bin-packing |
10-25% |
How many tasks run vs how many are needed? |
| Savings Plans |
20-40% on committed |
Is the workload steady-state 24/7? |
| Provisioned capacity |
Eliminates cold-start scale-up cost |
Is the traffic predictable? |
Quick navigation
- Step 0 — Capture the optimization target (task def, service, metrics).
- Step 1 — Map to an optimization category (A-G).
- Step 2 — RIGHT_SIZE: CPU/memory combination analysis.
- Step 3 — SPOT: Fargate Spot vs On-Demand evaluation.
- Step 4 — ARM64: Graviton migration evaluation.
- Step 5 — SCHEDULING: bin-packing and capacity provider efficiency.
- Step 6 — SAVINGS_PLANS: commitment-based discount evaluation.
- Step 7 — Root-cause catalog (top patterns + canonical fixes).
- Step 8 — Verify the recommendation.
- Step 9 — Decide VERDICT (OPTIMIZED / OPPORTUNITY_FOUND / ALREADY_OPTIMAL).
Process — Optimization decision tree (apply in order)
Step 0: Capture the optimization target
Gather these inputs. Each step below branches on which are available.
| Signal |
Source |
Why required |
| Task definition |
aws ecs describe-task-definition |
CPU/memory config, architecture, family |
| CloudWatch metrics |
get-metric-statistics CPUUtilization + MemoryUtilization |
Right-sizing signal |
| Service configuration |
aws ecs describe-services |
Capacity provider strategy, desired count, scheduling |
| Cost data |
aws ce get-cost-and-usage filtered by Fargate |
Baseline spend |
If the user has not provided the task definition or metrics, output:
NEED_MORE_INFO re-prompt template moved to
references/worked-examples.md.
Step 0 capture commands moved to
references/rightsizing-commands.md.
Step 1: Identify the optimization category
| Category |
Signal |
Diagnostic step |
| A. RIGHT_SIZE |
CPUUtilization avg < 50% or MemoryUtilization avg < 60% |
Step 2 |
| B. SPOT |
Workload is fault-tolerant (batch, workers, stateless); currently 100% On-Demand |
Step 3 |
| C. ARM64 |
Runtime is x86_64; language supports ARM64 (Java 11+, Python, Node.js, Go) |
Step 4 |
| D. SCHEDULING |
Tasks > needed capacity; no capacity provider strategy |
Step 5 |
| E. SAVINGS_PLANS |
Steady-state 24/7 workload on On-Demand |
Step 6 |
| F. ALREADY_OPTIMAL |
Right-sized, Spot/SP applied, ARM64, efficient scheduling |
Verdict: ALREADY_OPTIMAL |
| G. PROVISIONED |
Predictable traffic with cold-start scale-up latency |
Step 5 (capacity provider) |
Apply A before B before C. Right-sizing reduces the base; Spot and
ARM64 are multipliers on top. Savings Plans are evaluated last because
the commitment should be based on the post-optimized config.
Step 2: RIGHT_SIZE — CPU/memory combination analysis
Fargate charges per vCPU-hour and per GB-hour. An over-provisioned task
pays for resources it never uses. The right-sizing signal is
CloudWatch's CPUUtilization and MemoryUtilization, measured against the
task's configured limits.
Fargate allowed CPU/memory combinations
| CPU (vCPU) |
Memory (GB) |
| 0.25 |
0.5, 1, 2 |
| 0.5 |
1, 2, 3, 4 |
| 1 |
2, 3, 4, 5, 6, 7, 8 |
| 2 |
4, 5, 6, ..., 16 |
| 4 |
8, 9, 10, ..., 30 |
| 8 |
16, 17, 18, ..., 60 |
| 16 |
32, 33, 34, ..., 120 |
Decision table (apply to the task's current config):
| Metric signal |
Current config |
Recommended action |
| CPUUtilization avg < 30%, max < 50% |
1+ vCPU |
Drop to next-lower CPU combo |
| CPUUtilization avg 30-60%, max < 80% |
Any |
Consider dropping one combo if memory allows |
| CPUUtilization avg > 70%, max > 90% |
Any |
Under-provisioned — do NOT downsize |
| MemoryUtilization avg < 50% |
4+ GB |
Reduce memory within the same CPU tier |
| MemoryUtilization avg > 85% |
Any |
Memory-bound — do NOT downsize memory |
| CPUUtilization spikes to 100% for <5 min, then settles |
Any |
Use Application Auto Scaling, not upsize |
The combo-floor rule. When downsizing CPU, you may need to also
reduce memory (the memory range is constrained by the CPU tier). E.g.,
dropping from 2 vCPU / 10 GB to 1 vCPU means the max memory drops to 8
GB. Verify MemoryUtilization supports the new memory level.
The memory floor. Memory is less elastic than CPU. A JVM heap set
to 8 GB needs at least 8 GB task memory regardless of
MemoryUtilization averages. Check -Xmx / MaxRAMPercentage before
downsizing memory on Java tasks.
Step 2 diagnostic commands moved to
references/rightsizing-commands.md.
Savings estimation table moved to
references/fargate-pricing-matrix.md.
Step 3: SPOT — Fargate Spot vs On-Demand evaluation
Fargate Spot offers up to 70% savings for workloads that can tolerate
interruptions. Spot tasks can be reclaimed with a 2-minute warning.
Eligibility assessment:
| Workload characteristic |
Spot-eligible? |
Rationale |
| Batch processing, job workers |
YES |
Stateless, retriable |
| Stateless web/API (behind ALB) |
YES |
ALB health checks drain on interruption |
| Event-driven (SQS/Kinesis consumers) |
YES |
Messages return to queue on interruption |
| Scheduled tasks (cron) |
YES |
Retry on next schedule |
| Stateful services (DB, cache) |
NO |
Interruption loses in-memory state |
| Long-running singletons (leader election) |
NO |
Interruption disrupts leadership |
| WebSocket / SSE long-poll connections |
CAUTION |
Users disconnected on interruption; use reconnection logic |
Capacity provider strategy (the standard Spot pattern):
{
"capacityProviderStrategy": [
{
"capacityProvider": "FargateSpot",
"weight": 4,
"base": 0
},
{
"capacityProvider": "Fargate",
"weight": 1,
"base": 1
}
]
}
This places base: 1 On-Demand task (always running) and distributes
the rest 4:1 (Spot:On-Demand). For 10 desired tasks: 1 base On-Demand +
7 Spot + 2 On-Demand = ~80% Spot.
Interruption handling checklist:
- ECS sends a
SIGTERM 2 minutes before Spot reclamation.
- The app must handle
SIGTERM: finish in-flight requests, drain
connections, checkpoint state.
- Set
deploymentMinimumHealthyPercent > 0 so replacements launch
before old tasks terminate.
- For SQS consumers: use
visibilityTimeout > processing time so
interrupted messages return to the queue.
Savings estimation:
| Pricing |
2 vCPU / 4 GB hourly |
Monthly (730h) |
Savings |
| On-Demand |
$0.087 |
$63.51 |
— |
| Spot (approx) |
$0.026 |
$18.98 |
70% |
For 50 tasks at 2 vCPU / 4 GB: On-Demand = $3,176/month; 80% Spot =
~$1,200/month. Savings: ~$1,976/month.
Step 4: ARM64 — Graviton migration evaluation
ARM64 (Graviton2/Graviton3) is ~20% cheaper per vCPU-hour and per
GB-hour on Fargate. Most modern runtimes support ARM64 natively.
Runtime compatibility:
| Runtime |
ARM64 support |
Notes |
| Java (Corretto, OpenJDK) |
YES (Java 11+) |
No code changes; rebuild image |
| Python |
YES |
Pure Python: no changes. C extensions: rebuild wheels |
| Node.js |
YES |
No changes for pure JS; test native modules |
| Go |
YES |
Cross-compile: GOOS=linux GOARCH=arm64 go build |
| .NET |
YES (.NET 6+) |
Rebuild image |
| Ruby |
YES |
Pure Ruby: no changes. Gems with C exts: rebuild |
| Rust |
YES |
Cross-compile: cargo build --target aarch64-unknown-linux-gnu |
Migration steps:
- Build a multi-arch image:
docker buildx build --platform linux/amd64,linux/arm64 -t <repo>:<tag> --push.
- Update the task definition: set
runtimePlatform.cpuArchitecture: "ARM64".
- Deploy a canary service with 1 ARM64 task alongside the x86_64
service.
- Monitor for errors, latency differences, and memory usage (ARM64
may use slightly different memory characteristics).
- Cut over the service to ARM64 once validated.
Pricing comparison (us-east-1, On-Demand, 2026):
| Config |
x86_64 hourly |
ARM64 hourly |
ARM64 savings |
| 1 vCPU / 2 GB |
$0.0430 |
$0.0344 |
20% |
| 2 vCPU / 4 GB |
$0.0870 |
$0.0696 |
20% |
| 4 vCPU / 8 GB |
$0.1730 |
$0.1384 |
20% |
Stacking with Spot: ARM64 + Spot is the cheapest combination.
ARM64 Spot is ~76% cheaper than x86_64 On-Demand.
Step 5: SCHEDULING — bin-packing and capacity provider efficiency
Task scheduling efficiency is about running the minimum number of tasks
needed to handle the load, with auto scaling that tracks demand.
Common inefficiencies:
| Pattern |
Problem |
Fix |
| Static desired count = 10, traffic drops 80% at night |
Paying for idle tasks |
Application Auto Scaling on CPU/ALB request count |
| desiredCount = 20, but 5 tasks handle peak |
Over-provisioned service |
Lower desiredCount; add auto scaling |
| minimumHealthyPercent = 200 during deploy |
Doubles task count during rollout |
Set to 100 (ECS maintains desired count during deploy) |
| maximumPercent = 400 during deploy |
Allows 4x tasks during rollout |
Set to 200 |
| No capacity provider strategy; 100% Fargate On-Demand |
Missing Spot savings |
Add FargateSpot capacity provider (Step 3) |
| Provisioned capacity for unpredictable traffic |
Paying for idle baseline |
Evaluate if traffic is truly unpredictable; if predictable, provisioned is correct |
Auto scaling policy command moved to
references/rightsizing-commands.md.
Target 60% CPU gives headroom for traffic spikes while avoiding
over-provisioning. ScaleInCooldown of 300s prevents flapping.
Step 6: SAVINGS_PLANS — commitment-based discount evaluation
Compute Savings Plans apply to Fargate, EC2, and Lambda. A 1-year or
3-year commitment provides a discount on the per-vCPU-hour and per-GB-hour
rate.
When Savings Plans make sense:
| Workload pattern |
SP recommendation |
Rationale |
| Steady-state 24/7 (always-on services) |
1yr or 3yr SP |
Commit to the baseline; On-Demand for spikes |
| Business-hours only (8h/day, 5d/wk) |
Do NOT use SP |
Only 34% utilization; SP wastes off-hours commitment |
| Spiky / unpredictable |
Do NOT use SP |
Cannot predict the commit level |
| Multi-service (Fargate + EC2 + Lambda) |
YES — SP covers all |
Compute SP is flexible across services |
Savings Plan discount rates (approximate, us-east-1, 2026):
| Commitment |
Discount vs On-Demand |
| 1-year, no upfront |
~20% |
| 1-year, all upfront |
~28% |
| 3-year, no upfront |
~38% |
| 3-year, all upfront |
~48% |
Key rule: Commit to the steady-state baseline (the minimum number
of tasks that run 24/7). The SP covers the baseline; On-Demand or Spot
handles spikes above the baseline. Over-committing wastes money;
under-committing leaves savings on the table.
Step 6 diagnostic commands moved to
references/rightsizing-commands.md.
Step 7: Map to root-cause catalog
| # |
Pattern |
Category |
Fix |
Est. savings |
| 1 |
CPUUtilization avg < 30% on 2+ vCPU task |
RIGHT_SIZE |
Drop to next-lower CPU combo |
30-50% |
| 2 |
MemoryUtilization avg < 50% on 4+ GB task |
RIGHT_SIZE |
Reduce memory within CPU tier |
10-25% |
| 3 |
100% On-Demand, fault-tolerant workload |
SPOT |
Capacity provider with Spot base |
Up to 70% |
| 4 |
x86_64 task, ARM64-compatible runtime |
ARM64 |
Rebuild image for arm64; update task def |
~20% |
| 5 |
Static desired count, no auto scaling |
SCHEDULING |
Application Auto Scaling on CPU |
20-40% |
| 6 |
No Savings Plans, steady-state 24/7 |
SAVINGS_PLANS |
1yr or 3yr Compute SP |
20-48% |
| 7 |
minimumHealthyPercent = 200 during deploy |
SCHEDULING |
Set to 100 |
Eliminates deploy-time doubling |
| 8 |
ARM64 + Spot + SP all applicable |
ALL |
Stack all three |
80-90% |
Step 8: Verify the recommendation
- For RIGHT_SIZE: deploy the smaller task def; monitor
CPUUtilization and MemoryUtilization for 7 days. If CPU avg > 70%,
revert. If MemoryUtilization > 85%, revert memory.
- For SPOT: deploy the capacity provider strategy with
base: 1
On-Demand; monitor for ServiceDeployments events showing Spot task
interruptions. If interruption rate is too high, adjust the
Spot:On-Demand weight.
- For ARM64: deploy a canary task first; compare error rate and
latency for 24-48 hours before full cutover.
- For SCHEDULING: monitor the auto scaling target for 7 days;
verify
ScaleOutCooldown catches traffic spikes.
- For SAVINGS_PLANS: start with a 1-year, no-upfront plan at the
current baseline; adjust the commitment after 1 month of observed
utilization.
Step 9: Decide — OPTIMIZED vs OPPORTUNITY_FOUND vs ALREADY_OPTIMAL
- OPPORTUNITY_FOUND. At least one optimization dimension has a
clear recommendation with estimated savings. Output RECOMMENDATION
and ESTIMATED_SAVINGS.
- OPTIMIZED. The task/service has already been right-sized, is
using Spot/SP where applicable, and is on ARM64 where compatible.
No further action needed.
- ALREADY_OPTIMAL. The workload is already at the optimal
configuration across all dimensions.
STRICT output contract
TARGET: <task-definition>:<revision> (service <service> on cluster <cluster>)
VERDICT: OPPORTUNITY_FOUND | OPTIMIZED | ALREADY_OPTIMAL
REASON: <summary of findings across dimensions>
RECOMMENDATION:
1. <RIGHT_SIZE recommendation with old → new combo>
2. <SPOT recommendation with capacity provider strategy>
3. <ARM64 recommendation if applicable>
4. <SCHEDULING recommendation if applicable>
5. <SAVINGS_PLANS recommendation if applicable>
ESTIMATED_SAVINGS: $<monthly savings> ($<annual savings>)
MIGRATION_STEPS:
1. <specific step with AWS CLI or console action>
2. <verification step>
3. <rollback step>
Worked example — over-provisioned task + Spot opportunity
TARGET: order-processor:42 (service order-processor on cluster prod)
VERDICT: OPPORTUNITY_FOUND
REASON: Task is over-provisioned (CPU avg 18%, max 35% on 2 vCPU / 4
GB); workload is stateless and fault-tolerant but running 100%
On-Demand; runtime is Java 21 (ARM64 compatible).
RECOMMENDATION:
1. RIGHT_SIZE: drop from 2 vCPU / 4 GB to 1 vCPU / 2 GB (CPU avg
18%, max 35% — 1 vCPU has headroom at ~36% avg, ~70% max)
2. SPOT: add capacity provider strategy with FargateSpot weight 4,
Fargate base 1 (workload is stateless behind ALB)
3. ARM64: rebuild image for linux/arm64; set
runtimePlatform.cpuArchitecture = ARM64
ESTIMATED_SAVINGS: $2,470/month ($29,640/year)
- Right-size: 10 tasks × ($63.51 - $31.39) = $321/month
- Spot: 8 Spot tasks × $18.98 vs $31.39 = ~$99/month saved
- ARM64: 10 tasks × 20% × $25.11 avg = ~$50/month saved
- Combined stacking on the optimized base
MIGRATION_STEPS:
1. Register new task definition order-processor:43 with cpu=1024,
memory=2048, runtimePlatform.cpuArchitecture=ARM64
2. Build multi-arch image: docker buildx build --platform
linux/amd64,linux/arm64 -t <repo>:v43 --push
3. Create FargateSpot capacity provider on the cluster
4. Update service with capacity provider strategy: Spot weight 4
base 0, Fargate weight 1 base 1
5. Monitor CPUUtilization for 7 days; revert if avg > 70%
Expert heuristic — "Right-size first, pricing model second, commitment third"
Expert heuristic reasoning moved to
references/advanced-patterns.md.
Anti-Patterns — NEVER
NEVER downsize a task without checking MemoryUtilization
separately from CPUUtilization. CPU and memory have different
dynamics: a task at 15% CPU may be at 90% memory. Downsizing based on
CPU alone can cause OOMKills. Always check both metrics.
NEVER recommend Fargate Spot for stateful services (databases,
caches, session stores) without explicit confirmation that the
workload can handle interruption. Spot reclamation sends SIGTERM
with 2 minutes notice; in-memory state is lost. Spot is for
fault-tolerant, stateless, or retriable workloads.
NEVER commit to a Savings Plan based on the pre-optimization
spend. Always right-size first, then evaluate Spot/ARM64, then
commit the SP to the optimized steady-state baseline. Committing to
the pre-optimization baseline locks in the waste.
NEVER assume a Java task's memory is CPU-scalable. JVM heap
(-Xmx or MaxRAMPercentage) pins the memory floor. A JVM with
-XX:MaxRAMPercentage=75 on a 4 GB task uses 3 GB heap. Downsizing
to 2 GB without adjusting the JVM flag will OOMKill the task.
NEVER skip the canary phase for ARM64 migration. ARM64 has
different memory characteristics and potential library
incompatibilities. Deploy a single ARM64 task alongside x86_64 and
monitor for 24-48 hours before full cutover.
NEVER set minimumHealthyPercent to 200 for cost savings
reasons. This is a deployment safety setting, not a cost setting.
Setting it to 100 is fine for stateless services, but the motivation
should be deployment speed, not cost.
NEVER rely on the Fargate allowed-combo table from memory without
verifying the memory range for the target CPU tier. The combos are
not arbitrary; each CPU tier has a constrained memory range. Verify
the desired combo exists before recommending it.
Recent AWS features (2024-2026)
Recent AWS features moved to
references/advanced-patterns.md.
References
See references/fargate-pricing-matrix.md for the full pricing
reference (all CPU/memory combos, Spot vs On-Demand, x86_64 vs ARM64,
regional rate notes), and references/rightsizing-commands.md for the
canonical command script for each optimization dimension.
References (load on demand)
- references/advanced-patterns.md — mindset, right-size/pricing/commitment heuristic, recent AWS features (moved from this file)
- references/worked-examples.md — NEED_MORE_INFO re-prompt template (moved from this file)
- references/fargate-pricing-matrix.md — full pricing matrix, Spot/ARM64/Savings Plans rates (savings-estimation table moved from this file appended)
- references/rightsizing-commands.md — canonical per-dimension command script (Step 0/2/5/6 listings moved from this file appended)
Domain
AWS CloudOps / Fargate Compute FinOps & Container Cost Optimization.
AWS documentation
1---2name: fargate-cost-optimizer3description: 'Optimises AWS Fargate cost across seven dimensions: task right-sizing (CPU/memory from 28 allowed combos, CloudWatch CPUUtilization and MemoryUtilization analysis), Fargate Spot vs On-Demand (up to 70% savings for fault-tolerant workloads), ARM64/Graviton migration (20% cheaper), task scheduling/bin-packing via capacity providers, Savings Plans (1yr/3yr commitment for steady-state), and latest features (Fargate EFA for HPC/ML, Fargate instance storage for high-I/O). Reads CloudWatch metrics, ECS configs, and Cost Explorer data. Emits OPPORTUNITY_FOUND with recommendation and estimated savings, OPTIMIZED, or ALREADY_OPTIMAL. Use when reviewing Fargate spend, right-sizing ECS tasks, evaluating Spot/ARM64 migration, or a FinOps review of container spend.'4license: Apache-2.05compatibility: Agent runtime that reads SKILL.md (Claude Code, Cursor, Windsurf, Codex, Gemini). Offline recommendation classification works from pasted CloudWatch metrics, ECS task definitions, and Cost Explorer data. Live-account optimization uses aws ecs describe-task-definition, describe-services, describe-capacity-providers, aws cloudwatch get-metric-statistics (CPUUtilization, MemoryUtilization), aws ce get-cost-and-usage, aws ce get-reservation-utilization, and aws compute-optimizer...6metadata:7 source: https://skillmd.com/skills/jhkchan/fargate-cost-optimizer8 domain: aws-cloudops9 complexity: high10 requires_llm: 'true'11 phase: '3'12 supports_pipeline: 'true'13 entry_point: 'false'14 family: Compute15 task_type: optimize16 skill_class: capability17 lifecycle_status: active18 verdict_shape: OPTIMIZED | OPPORTUNITY_FOUND | ALREADY_OPTIMAL19 when_to_use: Optimising Fargate cost, right-sizing ECS task definitions (CPU and memory), evaluating Fargate Spot vs On-Demand capacity provider strategy, migrating x86_64 tasks to ARM64/Graviton, tuning task scheduling efficiency (bin-packing, capacity providers), evaluating Savings Plans for Fargate, or a FinOps review of container spend.20 when_not_to_use: EC2 instance rightsizing (use ec2-rightsizing-optimizer), Lambda cost optimization (use lambda-cost-optimizer), EKS cost optimization (use eks-cost-optimizer), or ECS task troubleshooting (task failures, deployment issues — use ecs-task-troubleshooter). This skill focuses on cost-driven optimization, not functional debugging.21 activation_triggers: optimise Fargate cost, Fargate right-sizing, Fargate CPU memory combo, Fargate Spot savings, Fargate capacity provider, Fargate ARM64 Graviton, Fargate Savings Plans, Fargate bin-packing, Fargate task scheduling, Fargate FinOps, reduce Fargate bill, Fargate cost review, ECS task over-provisioned, Fargate EFA, Fargate instance storage22 invocation_schema: 'Input: either (a) a task definition ARN + live-account context, (b) CloudWatch metrics (CPUUtilization, MemoryUtilization) with at least 14 days of observation, OR (c) an ECS service configuration with capacity provider strategy. Output: a deterministic TARGET / VERDICT / REASON / RECOMMENDATION / ESTIMATED_SAVINGS / MIGRATION_STEPS block per task definition or service, where VERDICT is one of {OPTIMIZED, OPPORTUNITY_FOUND, ALREADY_OPTIMAL}.'23 version: 0.1.024 author: Jacky Chan — AWS Community Builder25 keywords: Fargate, ECS, cost optimization, right-sizing, task definition, CPU, memory, Fargate Spot, On-Demand, capacity provider, ARM64, Graviton, Savings Plans, bin-packing, task scheduling, EFA, instance storage, FinOps, Compute Optimizer, container26 tags: fargate, ecs, compute, cost-optimization, finops, rightsizing, graviton, spot, savings-plans27---2829# Fargate Cost Optimizer3031## Activation3233Activate this skill when the user reports Fargate cost concerns. Trigger34phrases: "optimise Fargate cost", "Fargate right-sizing", "Fargate CPU35memory combo", "Fargate Spot savings", "Fargate capacity provider",36"Fargate ARM64 Graviton", "Fargate Savings Plans", "Fargate bin-packing",37"Fargate FinOps", "reduce Fargate bill", "ECS task over-provisioned".3839## Mindset4041Mindset and optimization facts moved to42[references/advanced-patterns.md](references/advanced-patterns.md).4344## Quick reference — optimization dimensions4546| Dimension | Potential savings | First probe |47|---|---|---|48| Task right-sizing (CPU/memory) | 30-60% | CloudWatch CPUUtilization + MemoryUtilization (14-day avg + max) |49| Fargate Spot vs On-Demand | Up to 70% | Is the workload fault-tolerant? (batch, workers, stateless web) |50| ARM64/Graviton migration | ~20% | Is the image ARM64-compatible? What runtime/language? |51| Capacity provider bin-packing | 10-25% | How many tasks run vs how many are needed? |52| Savings Plans | 20-40% on committed | Is the workload steady-state 24/7? |53| Provisioned capacity | Eliminates cold-start scale-up cost | Is the traffic predictable? |5455## Quick navigation5657- **Step 0** — Capture the optimization target (task def, service, metrics).58- **Step 1** — Map to an optimization category (A-G).59- **Step 2** — RIGHT_SIZE: CPU/memory combination analysis.60- **Step 3** — SPOT: Fargate Spot vs On-Demand evaluation.61- **Step 4** — ARM64: Graviton migration evaluation.62- **Step 5** — SCHEDULING: bin-packing and capacity provider efficiency.63- **Step 6** — SAVINGS_PLANS: commitment-based discount evaluation.64- **Step 7** — Root-cause catalog (top patterns + canonical fixes).65- **Step 8** — Verify the recommendation.66- **Step 9** — Decide VERDICT (OPTIMIZED / OPPORTUNITY_FOUND / ALREADY_OPTIMAL).6768## Process — Optimization decision tree (apply in order)6970### Step 0: Capture the optimization target7172Gather these inputs. Each step below branches on which are available.7374| Signal | Source | Why required |75|---|---|---|76| **Task definition** | `aws ecs describe-task-definition` | CPU/memory config, architecture, family |77| **CloudWatch metrics** | `get-metric-statistics` CPUUtilization + MemoryUtilization | Right-sizing signal |78| **Service configuration** | `aws ecs describe-services` | Capacity provider strategy, desired count, scheduling |79| **Cost data** | `aws ce get-cost-and-usage` filtered by Fargate | Baseline spend |8081If the user has not provided the task definition or metrics, output:8283NEED_MORE_INFO re-prompt template moved to84[references/worked-examples.md](references/worked-examples.md).8586Step 0 capture commands moved to87[references/rightsizing-commands.md](references/rightsizing-commands.md).8889### Step 1: Identify the optimization category9091| Category | Signal | Diagnostic step |92|---|---|---|93| **A. RIGHT_SIZE** | CPUUtilization avg < 50% or MemoryUtilization avg < 60% | Step 2 |94| **B. SPOT** | Workload is fault-tolerant (batch, workers, stateless); currently 100% On-Demand | Step 3 |95| **C. ARM64** | Runtime is x86_64; language supports ARM64 (Java 11+, Python, Node.js, Go) | Step 4 |96| **D. SCHEDULING** | Tasks > needed capacity; no capacity provider strategy | Step 5 |97| **E. SAVINGS_PLANS** | Steady-state 24/7 workload on On-Demand | Step 6 |98| **F. ALREADY_OPTIMAL** | Right-sized, Spot/SP applied, ARM64, efficient scheduling | Verdict: ALREADY_OPTIMAL |99| **G. PROVISIONED** | Predictable traffic with cold-start scale-up latency | Step 5 (capacity provider) |100101**Apply A before B before C.** Right-sizing reduces the base; Spot and102ARM64 are multipliers on top. Savings Plans are evaluated last because103the commitment should be based on the post-optimized config.104105### Step 2: RIGHT_SIZE — CPU/memory combination analysis106107Fargate charges per vCPU-hour and per GB-hour. An over-provisioned task108pays for resources it never uses. The right-sizing signal is109CloudWatch's CPUUtilization and MemoryUtilization, measured against the110task's configured limits.111112#### Fargate allowed CPU/memory combinations113114| CPU (vCPU) | Memory (GB) |115|---|---|116| 0.25 | 0.5, 1, 2 |117| 0.5 | 1, 2, 3, 4 |118| 1 | 2, 3, 4, 5, 6, 7, 8 |119| 2 | 4, 5, 6, ..., 16 |120| 4 | 8, 9, 10, ..., 30 |121| 8 | 16, 17, 18, ..., 60 |122| 16 | 32, 33, 34, ..., 120 |123124**Decision table (apply to the task's current config):**125126| Metric signal | Current config | Recommended action |127|---|---|---|128| CPUUtilization avg < 30%, max < 50% | 1+ vCPU | Drop to next-lower CPU combo |129| CPUUtilization avg 30-60%, max < 80% | Any | Consider dropping one combo if memory allows |130| CPUUtilization avg > 70%, max > 90% | Any | Under-provisioned — do NOT downsize |131| MemoryUtilization avg < 50% | 4+ GB | Reduce memory within the same CPU tier |132| MemoryUtilization avg > 85% | Any | Memory-bound — do NOT downsize memory |133| CPUUtilization spikes to 100% for <5 min, then settles | Any | Use Application Auto Scaling, not upsize |134135**The combo-floor rule.** When downsizing CPU, you may need to also136reduce memory (the memory range is constrained by the CPU tier). E.g.,137dropping from 2 vCPU / 10 GB to 1 vCPU means the max memory drops to 8138GB. Verify MemoryUtilization supports the new memory level.139140**The memory floor.** Memory is less elastic than CPU. A JVM heap set141to 8 GB needs at least 8 GB task memory regardless of142MemoryUtilization averages. Check `-Xmx` / `MaxRAMPercentage` before143downsizing memory on Java tasks.144145Step 2 diagnostic commands moved to146[references/rightsizing-commands.md](references/rightsizing-commands.md).147148Savings estimation table moved to149[references/fargate-pricing-matrix.md](references/fargate-pricing-matrix.md).150151### Step 3: SPOT — Fargate Spot vs On-Demand evaluation152153Fargate Spot offers up to 70% savings for workloads that can tolerate154interruptions. Spot tasks can be reclaimed with a 2-minute warning.155156**Eligibility assessment:**157158| Workload characteristic | Spot-eligible? | Rationale |159|---|---|---|160| Batch processing, job workers | YES | Stateless, retriable |161| Stateless web/API (behind ALB) | YES | ALB health checks drain on interruption |162| Event-driven (SQS/Kinesis consumers) | YES | Messages return to queue on interruption |163| Scheduled tasks (cron) | YES | Retry on next schedule |164| Stateful services (DB, cache) | NO | Interruption loses in-memory state |165| Long-running singletons (leader election) | NO | Interruption disrupts leadership |166| WebSocket / SSE long-poll connections | CAUTION | Users disconnected on interruption; use reconnection logic |167168**Capacity provider strategy (the standard Spot pattern):**169170```json171{172 "capacityProviderStrategy": [173 {174 "capacityProvider": "FargateSpot",175 "weight": 4,176 "base": 0177 },178 {179 "capacityProvider": "Fargate",180 "weight": 1,181 "base": 1182 }183 ]184}185```186187This places `base: 1` On-Demand task (always running) and distributes188the rest 4:1 (Spot:On-Demand). For 10 desired tasks: 1 base On-Demand +1897 Spot + 2 On-Demand = ~80% Spot.190191**Interruption handling checklist:**192- ECS sends a `SIGTERM` 2 minutes before Spot reclamation.193- The app must handle `SIGTERM`: finish in-flight requests, drain194 connections, checkpoint state.195- Set `deploymentMinimumHealthyPercent` > 0 so replacements launch196 before old tasks terminate.197- For SQS consumers: use `visibilityTimeout` > processing time so198 interrupted messages return to the queue.199200**Savings estimation:**201202| Pricing | 2 vCPU / 4 GB hourly | Monthly (730h) | Savings |203|---|---|---|---|204| On-Demand | $0.087 | $63.51 | — |205| Spot (approx) | $0.026 | $18.98 | 70% |206207For 50 tasks at 2 vCPU / 4 GB: On-Demand = $3,176/month; 80% Spot =208~$1,200/month. Savings: ~$1,976/month.209210### Step 4: ARM64 — Graviton migration evaluation211212ARM64 (Graviton2/Graviton3) is ~20% cheaper per vCPU-hour and per213GB-hour on Fargate. Most modern runtimes support ARM64 natively.214215**Runtime compatibility:**216217| Runtime | ARM64 support | Notes |218|---|---|---|219| Java (Corretto, OpenJDK) | YES (Java 11+) | No code changes; rebuild image |220| Python | YES | Pure Python: no changes. C extensions: rebuild wheels |221| Node.js | YES | No changes for pure JS; test native modules |222| Go | YES | Cross-compile: `GOOS=linux GOARCH=arm64 go build` |223| .NET | YES (.NET 6+) | Rebuild image |224| Ruby | YES | Pure Ruby: no changes. Gems with C exts: rebuild |225| Rust | YES | Cross-compile: `cargo build --target aarch64-unknown-linux-gnu` |226227**Migration steps:**2281. Build a multi-arch image: `docker buildx build --platform229 linux/amd64,linux/arm64 -t <repo>:<tag> --push`.2302. Update the task definition: set231 `runtimePlatform.cpuArchitecture: "ARM64"`.2323. Deploy a canary service with 1 ARM64 task alongside the x86_64233 service.2344. Monitor for errors, latency differences, and memory usage (ARM64235 may use slightly different memory characteristics).2365. Cut over the service to ARM64 once validated.237238**Pricing comparison (us-east-1, On-Demand, 2026):**239240| Config | x86_64 hourly | ARM64 hourly | ARM64 savings |241|---|---|---|---|242| 1 vCPU / 2 GB | $0.0430 | $0.0344 | 20% |243| 2 vCPU / 4 GB | $0.0870 | $0.0696 | 20% |244| 4 vCPU / 8 GB | $0.1730 | $0.1384 | 20% |245246**Stacking with Spot:** ARM64 + Spot is the cheapest combination.247ARM64 Spot is ~76% cheaper than x86_64 On-Demand.248249### Step 5: SCHEDULING — bin-packing and capacity provider efficiency250251Task scheduling efficiency is about running the minimum number of tasks252needed to handle the load, with auto scaling that tracks demand.253254**Common inefficiencies:**255256| Pattern | Problem | Fix |257|---|---|---|258| Static desired count = 10, traffic drops 80% at night | Paying for idle tasks | Application Auto Scaling on CPU/ALB request count |259| desiredCount = 20, but 5 tasks handle peak | Over-provisioned service | Lower desiredCount; add auto scaling |260| minimumHealthyPercent = 200 during deploy | Doubles task count during rollout | Set to 100 (ECS maintains desired count during deploy) |261| maximumPercent = 400 during deploy | Allows 4x tasks during rollout | Set to 200 |262| No capacity provider strategy; 100% Fargate On-Demand | Missing Spot savings | Add FargateSpot capacity provider (Step 3) |263| Provisioned capacity for unpredictable traffic | Paying for idle baseline | Evaluate if traffic is truly unpredictable; if predictable, provisioned is correct |264265Auto scaling policy command moved to266[references/rightsizing-commands.md](references/rightsizing-commands.md).267268Target 60% CPU gives headroom for traffic spikes while avoiding269over-provisioning. `ScaleInCooldown` of 300s prevents flapping.270271### Step 6: SAVINGS_PLANS — commitment-based discount evaluation272273Compute Savings Plans apply to Fargate, EC2, and Lambda. A 1-year or2743-year commitment provides a discount on the per-vCPU-hour and per-GB-hour275rate.276277**When Savings Plans make sense:**278279| Workload pattern | SP recommendation | Rationale |280|---|---|---|281| Steady-state 24/7 (always-on services) | 1yr or 3yr SP | Commit to the baseline; On-Demand for spikes |282| Business-hours only (8h/day, 5d/wk) | Do NOT use SP | Only 34% utilization; SP wastes off-hours commitment |283| Spiky / unpredictable | Do NOT use SP | Cannot predict the commit level |284| Multi-service (Fargate + EC2 + Lambda) | YES — SP covers all | Compute SP is flexible across services |285286**Savings Plan discount rates (approximate, us-east-1, 2026):**287288| Commitment | Discount vs On-Demand |289|---|---|290| 1-year, no upfront | ~20% |291| 1-year, all upfront | ~28% |292| 3-year, no upfront | ~38% |293| 3-year, all upfront | ~48% |294295**Key rule:** Commit to the steady-state baseline (the minimum number296of tasks that run 24/7). The SP covers the baseline; On-Demand or Spot297handles spikes above the baseline. Over-committing wastes money;298under-committing leaves savings on the table.299300Step 6 diagnostic commands moved to301[references/rightsizing-commands.md](references/rightsizing-commands.md).302303### Step 7: Map to root-cause catalog304305| # | Pattern | Category | Fix | Est. savings |306|---|---|---|---|---|307| 1 | CPUUtilization avg < 30% on 2+ vCPU task | RIGHT_SIZE | Drop to next-lower CPU combo | 30-50% |308| 2 | MemoryUtilization avg < 50% on 4+ GB task | RIGHT_SIZE | Reduce memory within CPU tier | 10-25% |309| 3 | 100% On-Demand, fault-tolerant workload | SPOT | Capacity provider with Spot base | Up to 70% |310| 4 | x86_64 task, ARM64-compatible runtime | ARM64 | Rebuild image for arm64; update task def | ~20% |311| 5 | Static desired count, no auto scaling | SCHEDULING | Application Auto Scaling on CPU | 20-40% |312| 6 | No Savings Plans, steady-state 24/7 | SAVINGS_PLANS | 1yr or 3yr Compute SP | 20-48% |313| 7 | minimumHealthyPercent = 200 during deploy | SCHEDULING | Set to 100 | Eliminates deploy-time doubling |314| 8 | ARM64 + Spot + SP all applicable | ALL | Stack all three | 80-90% |315316### Step 8: Verify the recommendation317318- **For RIGHT_SIZE:** deploy the smaller task def; monitor319 CPUUtilization and MemoryUtilization for 7 days. If CPU avg > 70%,320 revert. If MemoryUtilization > 85%, revert memory.321- **For SPOT:** deploy the capacity provider strategy with `base: 1`322 On-Demand; monitor for `ServiceDeployments` events showing Spot task323 interruptions. If interruption rate is too high, adjust the324 Spot:On-Demand weight.325- **For ARM64:** deploy a canary task first; compare error rate and326 latency for 24-48 hours before full cutover.327- **For SCHEDULING:** monitor the auto scaling target for 7 days;328 verify `ScaleOutCooldown` catches traffic spikes.329- **For SAVINGS_PLANS:** start with a 1-year, no-upfront plan at the330 current baseline; adjust the commitment after 1 month of observed331 utilization.332333### Step 9: Decide — OPTIMIZED vs OPPORTUNITY_FOUND vs ALREADY_OPTIMAL334335- **OPPORTUNITY_FOUND.** At least one optimization dimension has a336 clear recommendation with estimated savings. Output RECOMMENDATION337 and ESTIMATED_SAVINGS.338- **OPTIMIZED.** The task/service has already been right-sized, is339 using Spot/SP where applicable, and is on ARM64 where compatible.340 No further action needed.341- **ALREADY_OPTIMAL.** The workload is already at the optimal342 configuration across all dimensions.343344## STRICT output contract345346```text347TARGET: <task-definition>:<revision> (service <service> on cluster <cluster>)348VERDICT: OPPORTUNITY_FOUND | OPTIMIZED | ALREADY_OPTIMAL349REASON: <summary of findings across dimensions>350RECOMMENDATION:351 1. <RIGHT_SIZE recommendation with old → new combo>352 2. <SPOT recommendation with capacity provider strategy>353 3. <ARM64 recommendation if applicable>354 4. <SCHEDULING recommendation if applicable>355 5. <SAVINGS_PLANS recommendation if applicable>356ESTIMATED_SAVINGS: $<monthly savings> ($<annual savings>)357MIGRATION_STEPS:358 1. <specific step with AWS CLI or console action>359 2. <verification step>360 3. <rollback step>361```362363### Worked example — over-provisioned task + Spot opportunity364365```text366TARGET: order-processor:42 (service order-processor on cluster prod)367VERDICT: OPPORTUNITY_FOUND368REASON: Task is over-provisioned (CPU avg 18%, max 35% on 2 vCPU / 4369GB); workload is stateless and fault-tolerant but running 100%370On-Demand; runtime is Java 21 (ARM64 compatible).371RECOMMENDATION:372 1. RIGHT_SIZE: drop from 2 vCPU / 4 GB to 1 vCPU / 2 GB (CPU avg373 18%, max 35% — 1 vCPU has headroom at ~36% avg, ~70% max)374 2. SPOT: add capacity provider strategy with FargateSpot weight 4,375 Fargate base 1 (workload is stateless behind ALB)376 3. ARM64: rebuild image for linux/arm64; set377 runtimePlatform.cpuArchitecture = ARM64378ESTIMATED_SAVINGS: $2,470/month ($29,640/year)379 - Right-size: 10 tasks × ($63.51 - $31.39) = $321/month380 - Spot: 8 Spot tasks × $18.98 vs $31.39 = ~$99/month saved381 - ARM64: 10 tasks × 20% × $25.11 avg = ~$50/month saved382 - Combined stacking on the optimized base383MIGRATION_STEPS:384 1. Register new task definition order-processor:43 with cpu=1024,385 memory=2048, runtimePlatform.cpuArchitecture=ARM64386 2. Build multi-arch image: docker buildx build --platform387 linux/amd64,linux/arm64 -t <repo>:v43 --push388 3. Create FargateSpot capacity provider on the cluster389 4. Update service with capacity provider strategy: Spot weight 4390 base 0, Fargate weight 1 base 1391 5. Monitor CPUUtilization for 7 days; revert if avg > 70%392```393394## Expert heuristic — "Right-size first, pricing model second, commitment third"395396Expert heuristic reasoning moved to397[references/advanced-patterns.md](references/advanced-patterns.md).398399## Anti-Patterns — NEVER400401- **NEVER** downsize a task without checking MemoryUtilization402 separately from CPUUtilization. CPU and memory have different403 dynamics: a task at 15% CPU may be at 90% memory. Downsizing based on404 CPU alone can cause OOMKills. Always check both metrics.405406- **NEVER** recommend Fargate Spot for stateful services (databases,407 caches, session stores) without explicit confirmation that the408 workload can handle interruption. Spot reclamation sends SIGTERM409 with 2 minutes notice; in-memory state is lost. Spot is for410 fault-tolerant, stateless, or retriable workloads.411412- **NEVER** commit to a Savings Plan based on the pre-optimization413 spend. Always right-size first, then evaluate Spot/ARM64, then414 commit the SP to the optimized steady-state baseline. Committing to415 the pre-optimization baseline locks in the waste.416417- **NEVER** assume a Java task's memory is CPU-scalable. JVM heap418 (`-Xmx` or `MaxRAMPercentage`) pins the memory floor. A JVM with419 `-XX:MaxRAMPercentage=75` on a 4 GB task uses 3 GB heap. Downsizing420 to 2 GB without adjusting the JVM flag will OOMKill the task.421422- **NEVER** skip the canary phase for ARM64 migration. ARM64 has423 different memory characteristics and potential library424 incompatibilities. Deploy a single ARM64 task alongside x86_64 and425 monitor for 24-48 hours before full cutover.426427- **NEVER** set `minimumHealthyPercent` to 200 for cost savings428 reasons. This is a deployment safety setting, not a cost setting.429 Setting it to 100 is fine for stateless services, but the motivation430 should be deployment speed, not cost.431432- **NEVER** rely on the Fargate allowed-combo table from memory without433 verifying the memory range for the target CPU tier. The combos are434 not arbitrary; each CPU tier has a constrained memory range. Verify435 the desired combo exists before recommending it.436437## Recent AWS features (2024-2026)438439Recent AWS features moved to440[references/advanced-patterns.md](references/advanced-patterns.md).441442## References443444See `references/fargate-pricing-matrix.md` for the full pricing445reference (all CPU/memory combos, Spot vs On-Demand, x86_64 vs ARM64,446regional rate notes), and `references/rightsizing-commands.md` for the447canonical command script for each optimization dimension.448449## References (load on demand)450451- [references/advanced-patterns.md](references/advanced-patterns.md) — mindset, right-size/pricing/commitment heuristic, recent AWS features (moved from this file)452- [references/worked-examples.md](references/worked-examples.md) — NEED_MORE_INFO re-prompt template (moved from this file)453- [references/fargate-pricing-matrix.md](references/fargate-pricing-matrix.md) — full pricing matrix, Spot/ARM64/Savings Plans rates (savings-estimation table moved from this file appended)454- [references/rightsizing-commands.md](references/rightsizing-commands.md) — canonical per-dimension command script (Step 0/2/5/6 listings moved from this file appended)455456## Domain457458AWS CloudOps / Fargate Compute FinOps & Container Cost Optimization.459460## AWS documentation461462- **AWS Fargate pricing** — https://aws.amazon.com/fargate/pricing/463- **Fargate task definition CPU/memory** — https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-cpu-memory-error.html464- **Fargate Spot** — https://docs.aws.amazon.com/AmazonECS/latest/developerguide/fargate-capacity-providers.html465- **Graviton on AWS** — https://aws.amazon.com/ec2/graviton/466- **Compute Savings Plans** — https://docs.aws.amazon.com/savingsplans/latest/userguide/sp-compute.html467- **ECS capacity providers** — https://docs.aws.amazon.com/AmazonECS/latest/developerguide/cluster-capacity-providers.html468- **Application Auto Scaling for ECS** — https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-auto-scaling.html469- **Fargate EFA support** — https://docs.aws.amazon.com/AmazonECS/latest/developerguide/efa.html