AWS EC2 Reserved Instance Auditing

If you’re running instances atop AWS, you’re probably at least bleeding money. If you don’t know what reserved instances are and/or aren’t using them, you are hemorrhaging money.

One of the worst parts of AWS billing, is that they don’t care to make it clear which instances are getting metered under a reservation, and which aren’t, so it’s near impossible to really tell at any given moment what your reserved instance coverage is. To that end, I wrote a small script that uses the AWS API to look at your reserved instances, and your running instances, and give you actionable information.

In the below examples, for each availability zone (AZ) in the specified region, the instance type, Reserved Instance (RI) count, Instance in the “running” state count (I), and the Difference I-RI (D) are displayed. So a positive “D” is the number of instances not covered by RIs, and the absolute value of a negative “D” is the number of RIs more than instances at this point in time. You can run with –verbose if you forget the character abbreviations.

NOTE: This doesn’t enumerate all of your instances (0r even AZs), just the types that have differences between allocated reserved instances, and running instances. Because of this, you will never see a line with a Difference of zero.

# riaudit.rb --help
  --region, -r <s>:   AWS Region (default: us-east-1)
     --verbose, -v:   Spell out the variables
       --debug, -d:   Be noisy
        --help, -h:   Show this message

# riaudit.rb --region us-west-2

AZ: us-west-2c
    t1.micro RI: 0 I: 2 D: 2
    m1.small RI: 0 I: 3 D: 3
    m1.medium RI: 2 I: 3 D: 1

# riaudit.rb --region us-east-1

AZ: us-east-1d
    m1.small RI: 2 I: 4 D: 2
    c1.medium RI: 25 I: 23 D: -2
    m1.medium RI: 0 I: 1 D: 1

AZ: us-east-1c
    m1.small RI: 0 I: 5 D: 5
    c1.medium RI: 0 I: 1 D: 1
    m1.medium RI: 0 I: 2 D: 2

AZ: us-east-1e
    m3.xlarge RI: 0 I: 1 D: 1
    m1.small RI: 3 I: 4 D: 1
    c1.medium RI: 18 I: 19 D: 1

AZ: us-east-1a
    m1.small RI: 0 I: 3 D: 3
    t1.micro RI: 0 I: 3 D: 3
    m1.medium RI: 2 I: 1 D: -1

You can grab the script as a GitHub Gist. Pull requests welcome.

This entry was posted in Architecture, Coding, Work and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *