blog
Checking Amazon EC2 Reserved Instances
If you are using Amazon EC2 servers, you know that it is a lot cheaper if you purchase a reserved instance rather than paying hourly for servers that you intend to run continuously. On my projects, we typically have quite a few servers where we purchase “heavy utilization” reserved instances because we intend to run them day-in and day-out for many months. However, the Amazon Web Services management console makes it really difficult to tell if your currently running EC2 instances match up to reserved instances. And it’s also difficult to know when a reserved instance is about to expire so that you can purchase a new one.
On top of that, when you create a new account with Amazon, you get to run a t1.micro instance free for a year. They call this their “free tier.” But it is very difficult to tell when your free period is about to expire so that you can then purchase a reserved instance instead. So I wrote some PHP code to rectify all of these issues.
My code can output either HTML for a web browser, or it can send an HTML email to someone. I have it set up to send me an email every couple of weeks by using a cron job to check my two Amazon accounts. I also have it set up to show the results in a web page on an administrative server for the printui.com startup. The output looks something like this…
| Summary for Account
All running instances have a matching reserved instance Details for Account
|
|||||||||||||||||||||||||||||||||||||||||
If an instance will expire within two weeks, the summary will tell you exactly when it will expire. If a reserved instance has already expired, the results will show you which EC2 instance is affected.
You can download a ZIP file of the complete the source code from here:
To use it yourself, edit the config.php file and set the various values. The define’s that start with “G_smtp” are used to send the emails via SMTP. Note that you must have the PEAR Mail and Mail_Mime extensions installed for this to work. The $account array defines your Amazon accounts, including the date when the free tier started (i.e. the date you opened your Amazon account). This code has been tested with PHP 5.3.
This entry was posted on Sunday, March 30th, 2014 at 3:28 pm and is filed under Amazon Web Services, Cloud Computing . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
