AWS Compute Optimizer is a free service (no additional charge) that, given the right permissions and metrics, analyzes your resources and makes recommendations to help you avoid over-provisioned or under-provisioned resources across:
Compute Optimizer’s recommendations now also feed directly into Cost Optimization Hub (see Step 6), which is the single place to review rightsizing savings across all these resource types alongside Savings Plans and Reserved Instance opportunities.
Takeaway: when optimizing cost for compute (EC2, Lambda, Fargate), follow this order:
Doing step 2 before step 1 makes the optimization mostly meaningless — you’d be committing to pay for an instance size for 1 or 3 years without knowing whether it’s too powerful (wasteful) or too weak (can’t handle the workload).
AWS Compute Optimizer relies on metrics collected by CloudWatch over a 14-day lookback period by default (extendable up to 93 days with enhanced infrastructure metrics) to analyze and make recommendations, using metrics such as:
mem_used_percent (Linux) or Available MBytes (Windows)You can see the full metrics list here: Metrics analyzed by AWS Compute Optimizer. Custom metrics from the CloudWatch agent must be published under the namespace CWAgent for Compute Optimizer to pick them up.
You can use a different namespace to keep your own custom metrics organized in CloudWatch, but if you want full recommendations from AWS Compute Optimizer, the namespace CWAgent is required.
The Memory utilization metric is a custom metric, so it isn’t collected by default. Without it, EC2 sizing recommendations are less reliable, because they’d be based only on CPUUtilization. This is exactly why we installed the CloudWatch Agent in Step 5 — refer back to Step 4 and Step 5 if you need a refresher.
Example 1: AWS Compute Optimizer’s proposal for an EC2 instance when only the CPU utilization metric is available.
m5.xlarge with 4 vCPU and 16 GiB memoryr6g.large with 2 vCPU and 16 GiB memory
Estimated savings shown for illustration only — actual figures depend on your current instance’s on-demand price and Region.
Example 2: AWS Compute Optimizer’s proposal for the same EC2 instance once both CPU utilization and memory utilization are available.
m5.xlarge with 4 vCPU and 16 GiB memoryt4g.nano with 2 vCPU and 0.5 GiB memory
With the fuller metric set, Compute Optimizer’s recommendation is noticeably more aggressive and accurate — this is the effect of giving it complete data, which makes savings estimates far more trustworthy. It’s the same principle behind the “no real workload” caveat in Step 6: the recommendation is only as good as the data behind it.
AWS Compute Optimizer supports most current instance families, including C5, C6, M5, M6, R5, R6, T3, T4g, and more. See the up-to-date list here: EC2 instance requirements.
Some specialized families (GPU instances like G4/G5, and Mac instances) are not supported — check the same requirements page for the current exclusion list, since AWS periodically expands support.
AWS Compute Optimizer does not generate recommendations for Spot Instances.
Example 3: AWS Compute Optimizer’s proposal for an Auto Scaling group (ASG), such as one automatically created by AWS Elastic Beanstalk.
ASG configuration details:
t2.micro)

AWS Compute Optimizer’s recommendation:
t2.microt4g.micro, an example of a small hourly saving per instance
The recommendation is also reflected on the EC2 console:

An ASG with mismatched capacity values (e.g. desired=2, minimum=1, maximum=4) won’t receive optimization recommendations from AWS Compute Optimizer. (Learn more about Auto Scaling groups in the Amazon EC2 Auto Scaling documentation.)
Example 4: AWS Compute Optimizer’s proposal for an EBS volume

Example 5: AWS Compute Optimizer’s proposal for a Lambda function
The function is flagged as under-provisioned (memory under-provisioned)

Suggested memory increase:

If a target tracking policy is attached to the service’s CPU, Compute Optimizer only recommends memory sizing, and vice versa.
Example 6: AWS Compute Optimizer’s proposal for a Fargate service

In this section, we’ll opt in to AWS Compute Optimizer. If you’re signed in as an IAM user or role with AdministratorAccess, no extra permission setup is needed. But if you’re acting as a deployer for a client that follows least privilege, you’ll need to request the two policies below.
Create the service-linked role policy



{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "iam:CreateServiceLinkedRole",
"Resource": "arn:aws:iam::*:role/aws-service-role/compute-optimizer.amazonaws.com/AWSServiceRoleForComputeOptimizer*",
"Condition": {
"StringLike": {
"iam:AWSServiceName": "compute-optimizer.amazonaws.com"
}
}
},
{
"Effect": "Allow",
"Action": "iam:PutRolePolicy",
"Resource": "arn:aws:iam::*:role/aws-service-role/compute-optimizer.amazonaws.com/AWSServiceRoleForComputeOptimizer"
},
{
"Effect": "Allow",
"Action": "compute-optimizer:UpdateEnrollmentStatus",
"Resource": "*"
}
]
}

specific_service_linked_role_for_Compute_Optimizer
Assign permissions to your IAM user

compute

Opt in to AWS Compute Optimizer
Compute Optimizer itself is free. You only pay when you act on a recommendation (changing an instance type, resizing a volume) or for the CloudWatch monitoring costs of metrics beyond the free tier.


For this lab, we choose Only this account. In a real business environment where Dev/Test and Production live in separate AWS accounts managed by AWS Organizations, you would instead choose All accounts within this organization to get recommendations across every member account.



As explained in Step 6, don’t be surprised if your ec2-rightsizing-lab instance shows up as “Not optimized” with a recommendation to downsize, or with “Insufficient data”, rather than one of the rich, multi-option examples shown in the theory section above. Those theory examples come from instances with real, sustained production traffic behind them over weeks — your lab instance has almost no load at all, so there’s very little for the algorithm to reason about. That’s the expected, correct behavior, not something to troubleshoot. The value of this step is confirming the opt-in and permissions workflow works end-to-end, so that when you point Compute Optimizer at a real workload later, you already know exactly where to look.