Idle Finder: what your idle EC2 and RDS machines cost

A free, read-only script that looks at your running EC2 instances and RDS databases, counts the hours in the last two weeks when each one sat idle, and tells you what switching it off for those hours would save. It runs on your computer with your own AWS credentials and sends nothing to us.

Download costcapper-idle-finder.py Source and issues on GitHub (one Python file, MIT licence)

Run it

You need Python 3.9 or later and boto3. Use any AWS profile that has the read-only permissions below.

pip install boto3
python3 costcapper-idle-finder.py                          # your default region
python3 costcapper-idle-finder.py --regions us-east-1 eu-west-1
python3 costcapper-idle-finder.py --all-regions --csv idle.csv

Options: --days (history to read, default 14), --threshold (an hour counts as idle when maximum CPU is below this percent, default 5), --profile, and --csv to save the results.

Example output

From a test account with four machines that are busy in working hours only:

Region         Type Name or ID       Size           24/7 a month  Idle  Could save
us-east-1      RDS  staging-db       db.r7g.large           $174   70%        $123
us-east-1      EC2  ci-runner        m7i.xlarge             $147   82%        $121
us-east-1      EC2  dev-box-sam      t3.large                $61   70%         $43
us-east-1      EC2  demo-eu          t4g.medium              $25   96%         $24

Possible saving: about $310 a month, from switching machines off in the hours they were idle.

The permissions it needs

Only reads. It never starts, stops, tags or changes anything: every AWS call in it is a describe, a get or a list.

{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Action": [
      "ec2:DescribeInstances",
      "ec2:DescribeRegions",
      "rds:DescribeDBInstances",
      "cloudwatch:GetMetricData",
      "pricing:GetProducts"
    ],
    "Resource": "*"
  }]
}

How it works out the numbers

  • Idle hours: CloudWatch's hourly maximum CPU for each machine over the last 14 days. An hour under 5% counts as idle. Machines that are busy with disk or network but not CPU will look idler than they are, so treat the list as a starting point.
  • Prices: on-demand rates from the AWS Price List API for each machine's type and region. EC2 uses the Linux price; Windows and licensed instances are flagged. Savings Plans and Reserved Instances lower the real saving.
  • Saving: the monthly price (730 hours) times the share of hours that were idle. Storage is still charged while a machine is stopped.
  • Flagged, not counted as easy wins: Auto Scaling group members, Spot instances, RDS read replicas (AWS can't stop them) and Aurora instances (stop the cluster instead).

What to do with the list

Machines near the top that are idle most of the week are the ones worth switching off outside working hours. You can do that with a Lambda and EventBridge Scheduler, with AWS's own schedulers, or with CostCapper, which adds a button for whoever needs a machine outside the schedule. Prices for common sizes are in the idle cost table.