All posts

Find hidden AWS costs with Compute Optimizer and Cost Optimization Hub

How to turn on AWS Cost Optimization Hub and Compute Optimizer, what they cost, the CLI to pull your savings, and the memory metric that stops bad right-sizing.

Type
Guide
Published
Updated
Reading time
7 min
Author
Rajesh Govada
Topics
aws · finops · cost-optimization

Cost Optimization Hub is a free AWS Billing and Cost Management feature that gathers savings recommendations from all your accounts and Regions into one list: right-sizing, idle resources to delete, Savings Plans and Reserved Instances. It gets its right-sizing and idle findings from Compute Optimizer, so you turn on both.

Neither tool costs anything to turn on, and together they cover the first things I look at when a startup’s AWS bill keeps climbing. This guide covers enabling both, what they find, the CLI to pull the list, and the one setting that stops them recommending instances that are too small.

What they cost

  • Cost Optimization Hub: no charge.
  • Compute Optimizer: no charge for recommendations based on the last 14 days of metrics.
  • Compute Optimizer enhanced infrastructure metrics: optional and paid. It looks at up to three months of history instead of 14 days, for EC2 instances, Auto Scaling groups and RDS. AWS lists it at $0.0003360215 per resource per hour, about $0.25 a month for a resource that runs all month.
  • CloudWatch agent metrics (the memory data below): each metric the agent sends is a custom metric. In US East that is $0.30 per metric per month after the first 10 free ones, so keep the agent config small.

Check the Compute Optimizer pricing page and CloudWatch pricing for your Region before you turn on the paid parts.

Enable Compute Optimizer

Compute Optimizer analyzes EC2 instances, Auto Scaling groups, EBS volumes, Lambda functions, ECS services on Fargate, and RDS and Aurora databases against their actual utilization. It tells you when something is over-provisioned, under-provisioned, idle, or running on an older instance family.

Turn on Cost Explorer first. Compute Optimizer uses Cost Explorer’s billing data to put a dollar figure on each recommendation.

Then opt in from the Compute Optimizer console. If you use AWS Organizations, opt in from the management account and include member accounts to cover the whole organization:

aws compute-optimizer update-enrollment-status \
  --status Active \
  --include-member-accounts

The first analysis can take up to 24 hours. EC2 instances need at least 30 hours of CloudWatch metrics in the past 14 days before they get a recommendation, so a server you launched yesterday won’t show up yet.

What Compute Optimizer finds

Once it has enough data, Compute Optimizer flags resources like these:

  • Over-provisioned: you’re paying for capacity you’re not using. An m5.2xlarge running at 8% CPU belongs on something much smaller.
  • Under-provisioned: the instance is maxing out and affecting performance. Cheaper to right-size now than debug latency issues later.
  • Older instance family: running m4 or c4 when a current generation, or Graviton, would be cheaper for the same work. Graviton is a different CPU architecture, so test your build on Arm before you switch.
  • Idle resources: instances and volumes doing almost nothing, which you can stop or delete.
  • EBS volumes: gp2 volumes that should be gp3, or volumes with provisioned IOPS you’re not using.

Each recommendation also has a performance risk score from 0 to 4. Zero means the recommended size should always have enough headroom; the higher the number, the more you should test before switching.

List your EC2 recommendations from the CLI:

aws compute-optimizer get-ec2-instance-recommendations \
  --query "instanceRecommendations[].{
    Instance:instanceArn,
    Current:currentInstanceType,
    Finding:finding,
    Recommended:recommendationOptions[0].instanceType,
    Risk:recommendationOptions[0].performanceRisk,
    Savings:recommendationOptions[0].savingsOpportunity.estimatedMonthlySavings.value}" \
  --output table

This gives you a table of every instance with its current type, finding, the top recommended type, its performance risk and the estimated monthly saving.

Install the CloudWatch agent for memory metrics

Most setups miss this: EC2 doesn’t report memory use to CloudWatch on its own. Without memory data, Compute Optimizer recommends from CPU, network and disk alone, which can suggest a size that runs out of memory.

Install the CloudWatch agent so it reports memory. On Linux, Compute Optimizer reads mem_used_percent in the CWAgent namespace. On Windows, it reads Available MBytes.

Amazon Linux / RHEL

sudo yum install -y amazon-cloudwatch-agent

Ubuntu / Debian

wget https://amazoncloudwatch-agent.s3.amazonaws.com/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb
sudo dpkg -i amazon-cloudwatch-agent.deb
rm amazon-cloudwatch-agent.deb

Create the agent config at /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json:

{
  "metrics": {
    "namespace": "CWAgent",
    "metrics_collected": {
      "mem": {
        "measurement": ["mem_used_percent"],
        "metrics_collection_interval": 300
      },
      "disk": {
        "measurement": ["disk_used_percent"],
        "resources": ["/"],
        "metrics_collection_interval": 300
      }
    },
    "append_dimensions": {
      "InstanceId": "${aws:InstanceId}"
    }
  }
}

Keep the InstanceId dimension. If it’s missing or renamed, Compute Optimizer can’t match the memory data to the instance. The disk block is optional and only watches the root volume here; every extra mount you add is another custom metric on the bill.

Start the agent:

sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl \
  -a fetch-config \
  -m ec2 \
  -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json \
  -s

Verify it’s running:

sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a status

You should see "status": "running". The instance also needs an IAM role with the CloudWatchAgentServerPolicy managed policy so the agent can publish metrics. Give Compute Optimizer a couple of days with memory data before acting on its recommendations.

For fleets with many instances, deploy the agent through SSM Run Command or bake it into your AMI so every new instance reports memory from boot.

Cost Optimization Hub

Cost Optimization Hub collects recommendations from Compute Optimizer and from Billing and Cost Management into one dashboard. Two things make it more useful than reading each service separately:

  • It uses your real prices. Savings estimates take your existing Reserved Instances and Savings Plans into account.
  • It removes double counting. If you right-size an instance and also buy a Savings Plan for it, the hub doesn’t add both savings on top of each other.

It covers EC2 instances and Auto Scaling groups, EBS volumes, Lambda, ECS on Fargate, RDS and Aurora storage, ElastiCache, MemoryDB, DynamoDB, DocumentDB, OpenSearch and Redshift reservations, SageMaker, WorkSpaces, NAT gateways, and Savings Plans and Reserved Instances.

Enable it from the management account, including member accounts. The hub stores its recommendations in US East (N. Virginia), so the CLI calls use us-east-1 whichever Region your resources are in:

aws cost-optimization-hub update-enrollment-status \
  --status Active \
  --include-member-accounts \
  --region us-east-1

To include member accounts, your organization needs all features enabled. It can take up to 24 hours for the first recommendations to arrive.

Pull the 20 biggest savings:

aws cost-optimization-hub list-recommendations \
  --region us-east-1 \
  --query "reverse(sort_by(items[?estimatedMonthlySavings], &estimatedMonthlySavings))[:20].{
    Account:accountId,
    Type:currentResourceType,
    Resource:resourceId,
    Action:actionType,
    Effort:implementationEffort,
    MonthlySavings:estimatedMonthlySavings}" \
  --output table

I find this more useful than clicking through the console. The Effort column (VeryLow to VeryHigh) helps you pick the quick wins first.

A practical workflow

Here’s how I approach cost reviews:

  1. Turn on Cost Explorer, Compute Optimizer and Cost Optimization Hub from the management account, with member accounts included
  2. Install the CloudWatch agent on EC2 instances for memory metrics
  3. Wait a week so every resource has enough data
  4. Pull recommendations from the hub and sort by estimated savings
  5. Start with the easy wins: gp2-to-gp3 volume changes, idle resources, and older instance families
  6. Right-size carefully: check memory and the performance risk before downsizing. A 10% CPU instance with 85% memory use should not be downsized.
  7. Track savings month over month in Cost Explorer

Questions

Is Cost Optimization Hub free?

Yes. Cost Optimization Hub and Compute Optimizer’s standard recommendations cost nothing. You pay only if you turn on enhanced infrastructure metrics, and for any CloudWatch agent metrics you send.

What is the difference between Compute Optimizer and Cost Optimization Hub?

Compute Optimizer studies how your resources are used and recommends sizes. Cost Optimization Hub collects those recommendations plus Savings Plans and Reserved Instance advice into one list, priced with your discounts and without double counting.

Why doesn’t my instance have a recommendation?

It needs at least 30 hours of metrics in the last 14 days, the first analysis can take up to 24 hours, and Cost Explorer has to be on for savings figures to appear.

What these tools don’t cover

They price what is running and what you could buy. They don’t tell you about data transfer you didn’t plan for, log storage nobody reads, or backups you have never restored. A full cost review covers those too. If you want it done for you, the cloud cost and production audit runs these tools and the checks they miss, in five working days.