Sub topic 4
Using AWS Compute Optimizer recommendations
AWS Compute Optimizer is a service that analyzes the utilization metrics of your resources and suggests better-fitting configurations. This chapter covers how to enable it, what data it uses, how to read the output for EC2, and when to override it. It also covers how its Graviton suggestions fit into the migration work later in this tutorial.
This chapter assumes you have read the earlier chapters on CloudWatch utilization metrics and the right-sizing method. You should also be comfortable with the AWS CLI and with JSON output.
What Compute Optimizer does
Compute Optimizer reads the CloudWatch metrics that already exist for your resources. It applies machine-learning models trained on workload patterns across AWS and returns up to three alternative configurations per resource. It covers more than EC2:
- EC2 instances and Auto Scaling groups
- EBS volumes
- Lambda functions
- ECS services on Fargate
- RDS and Aurora databases
- Idle resources
This chapter focuses on EC2 instances. It automates the measuring step of the right-sizing method you already know, but it does not replace your judgment. It sees CPU, memory (if you provide it), network and disk. It does not know your release calendar, your licensing, or whether your software runs on Arm64.
Enabling Compute Optimizer
Compute Optimizer is opt-in. Until an account opts in, the recommendation calls fail. You can enroll one account or a whole AWS Organization from the management account.
# Opt in the current account
aws compute-optimizer update-enrollment-status --status Active
# From the Organizations management account, include all member accounts
aws compute-optimizer update-enrollment-status \
--status Active \
--include-member-accounts
# Confirm
aws compute-optimizer get-enrollment-statusAfter enrollment, wait for the first analysis. Compute Optimizer needs at least 30 hours of metric data for an instance before it produces a recommendation. Newly launched instances show no result until then.
What data it uses
The quality of a recommendation depends on its input. Three details matter most.
Lookback period. By default Compute Optimizer analyzes the last 14 days of metrics. If your workload has a monthly peak, such as end-of-month batch jobs, 14 days can miss it. The paid enhanced infrastructure metrics feature extends the lookback to three months. Turn it on for workloads with long cycles.
Memory. EC2 does not publish memory utilization to CloudWatch by default. Without it, Compute Optimizer decides on CPU, network and disk alone. It can then suggest a smaller instance with less memory than your application needs. Install the CloudWatch agent so that mem_used_percent reaches the CWAgent namespace. Compute Optimizer picks up the memory data once it is flowing.
Instance state. The recommendation reflects the instance as it ran during the window. If you resized it in the last week, the history is mixed. Wait for a clean window before trusting the result.
Reading the findings
Each instance receives a finding that classifies its current type.
| Finding | Meaning | Typical action |
|---|---|---|
| Underprovisioned | At least one resource (CPU, memory, network) is too small for the workload | Resize up, and treat it as a performance risk |
| Overprovisioned | At least one resource is larger than needed | Resize down, or change family |
| Optimized | The current type fits the observed load | Leave it alone |
An Overprovisioned instance also carries finding reason codes that say which dimension is oversized. Examples are CPUOverprovisioned, MemoryOverprovisioned, EBSThroughputOverprovisioned and NetworkBandwidthOverprovisioned. These tell you whether to drop one size in the same family or change to a different shape, such as moving from a general-purpose to a compute-optimized family.
Fetching recommendations with the CLI
The following command asks for the recommendations for one instance.
aws compute-optimizer get-ec2-instance-recommendations \
--instance-arns arn:aws:ec2:us-east-1:111122223333:instance/i-0123456789abcdef0The response is long. The fields you will use most are:
currentInstanceTypeandfindingfindingReasonCodesutilizationMetrics, which are the observed valueslookBackPeriodInDaysrecommendationOptions, a list of up to three alternatives
Use --query to cut the output down to a readable summary.
aws compute-optimizer get-ec2-instance-recommendations \
--instance-arns arn:aws:ec2:us-east-1:111122223333:instance/i-0123456789abcdef0 \
--query 'instanceRecommendations[0].{current:currentInstanceType,finding:finding,reasons:findingReasonCodes,options:recommendationOptions[].{type:instanceType,rank:rank,risk:performanceRisk,effort:migrationEffort,savings:savingsOpportunity.estimatedMonthlySavings.value}}'To list every Overprovisioned instance in the account, filter on the finding.
aws compute-optimizer get-ec2-instance-recommendations \
--filters name=Finding,values=Overprovisioned \
--query 'instanceRecommendations[].[instanceName,currentInstanceType,recommendationOptions[0].instanceType]' \
--output tableFor larger estates, export the data to S3 as CSV and analyze it in a spreadsheet or Athena.
aws compute-optimizer export-ec2-instance-recommendations \
--s3-destination-config bucket=my-optimizer-exports,keyPrefix=ec2/ \
--file-format CsvInterpreting a recommendation option
Each entry in recommendationOptions is a candidate. Read these fields together instead of picking on savings alone.
- rank: 1 is the best match according to Compute Optimizer. Options 2 and 3 are alternatives, often a different family.
- performanceRisk: a score from 0 (very low) to 4 (very high). It estimates the chance that the candidate will not meet the workload's needs. A large saving with a high risk is a trap, not a bargain.
- projectedUtilizationMetrics: what utilization would look like on the new type, assuming the same load. If projected CPU lands near 90 percent, you have left no headroom.
- platformDifferences: for example
Architecture,Hypervisor,NetworkInterfaceorStorageInterface. Each entry is a change you must check before moving. - migrationEffort: Compute Optimizer's estimate of how hard the move is. A same-architecture resize is "VeryLow". A move from x86-64 to Arm64 is rated higher, because software has to be rebuilt or verified.
- savingsOpportunity: estimated monthly savings, as a number and a percentage.
The Architecture entry in platformDifferences is where Graviton shows up. If rank 1 is an m7g or c7g type, the option implies a move to Arm64. Compute Optimizer does not know whether your software supports it. It only knows the CPU and memory profile fits.
Tuning the recommendations with preferences
Defaults suit many workloads, but you can adjust them. Compute Optimizer supports recommendation preferences at the organization, account or resource level.
- CPU vendor architecture: choose which architectures can appear in recommendations. If you have not yet assessed Arm64, restrict results to the current architecture so that every suggestion is a plain resize. When you are ready to evaluate Graviton, include Arm64.
- Utilization thresholds and headroom: change how conservative the CPU and memory sizing is. A latency-sensitive service may warrant more headroom than a batch worker.
- Lookback period: switch to the longer enhanced-metrics window.
- Savings estimation mode: base estimates on On-Demand prices, or after your existing Savings Plans and Reserved Instance discounts. The second mode gives a more honest number if you already hold commitments.
You set these with put-recommendation-preferences and view them with get-effective-recommendation-preferences. Check the current CLI help for the exact parameter names, because the preferences feature has grown over time.
Common errors and gotchas
- OptInRequiredException. The account is not enrolled. Run the enrollment command, then wait for analysis to finish.
- Empty results for a running instance. The instance has under 30 hours of data, or its metrics are missing. Check that detailed CloudWatch data is being produced.
- Acting on CPU-only findings. Without the CloudWatch agent, memory is invisible. Install it first.
- Following rank 1 blindly. The top option may change architecture, or may have a medium or high performance risk. Read the whole option.
- Ignoring a monthly peak. A 14-day window that misses the peak produces a recommendation that fails during the next close. Use the longer lookback or add your own CloudWatch review for the peak period.
- Resizing in the wrong order. Compute Optimizer's savings are based on a single resource. They do not account for Savings Plans you buy later. Resize first, and size commitments on the new baseline.
- Treating output as an instruction. The service gives a statistical suggestion. You must still validate it under realistic load, which the benchmarking chapter covers.
A practical workflow
- Enroll the account or organization, and enable the CloudWatch agent for memory on the instances that matter.
- Export all EC2 recommendations to S3 and sort by estimated monthly savings.
- Drop any row where
performanceRiskis 3 or higher, or where memory data is missing. - Split the remaining rows into same-architecture resizes and architecture changes.
- Send same-architecture resizes through a staged rollout, one non-production instance first.
- Send architecture changes to the compatibility check and benchmark steps in the following chapters.
- Re-run the export after two weeks on the new sizes. A resized instance should now be Optimized.
Exercise
Compute Optimizer reports an instance as Overprovisioned with the reason code CPUOverprovisioned, and its top option is an instance one size smaller with performanceRisk 1. Your CloudWatch agent is not installed. Is it safe to resize? What would you do first?
Show answer
It is not yet safe. Without the CloudWatch agent, Compute Optimizer did not see memory utilization, so the smaller instance may have too little memory. Install the agent, wait for enough data to cover the workload's peak, and fetch the recommendation again. If the finding still holds with memory included, resize one instance in a staged rollout.
Exercise
The rank 1 option for a web server is an m7g instance, with an Architecture entry in platformDifferences and a migrationEffort higher than the same-architecture options. What does this tell you, and what must you check before acting on it?
Show answer
The option moves the instance from x86-64 to Arm64 (Graviton). Compute Optimizer matched only the resource profile. Before acting, check that the operating system image, language runtime, native dependencies and container images all support Arm64, then benchmark under realistic load. If the check fails, choose a same-architecture option or restrict the architecture preference to the current CPU vendor.