Cycle AWS instances to save on your monthly bill.

More and more of us are moving our infrastructure into the cloud. Practically speaking this is just the way of things. What do you do when you have several Amazon Web Servers (instances) that  simply don't need to be on  all of the time? Ideally, by now Amazon should have come up with some kind of scheduler but they probably would charge for it. Or maybe they've intentionally left that up to third party products like this and this. The point is to DE-crease your monthly bill and with about an hour of work, you can do this yourself. To see how much you could save use the AWS Simple Monthly calculator. 

Please know, I was not the first to do this (by a Looooong shot). This Blog and This One were essential in helping me accomplish this task. I just wanted it on a Windows Micro & not with Python or Unix. 

First there are a few AWS setups you need: 

  1. AWS windows instance on the free tier. (Ok, Ok i know it's technically $14/year)
    • Windows logon for that instance.
  2. IAM new user with specific limited credentials.
    • Access Key & Secret Key for that new user.
  3. The Amazon API code downloaded and installed on that Free Server

The blogs I mention above also with these help documents from Amazon help will take you to a point then it's just a matter of scheduling a Windows Task to run the 1-line BAT files. One to stop the instances, One to start and One to Associate the Elastic IP Addresses. I gave a the instances about 5-minutes to wind up before I run the Associate BAT. 

Below are my notes on where I diverted from the instructions because I chose a Windows install:

On Mr Kulesza's blog: 
**About 1/2 way down he refers to 'Applying an IAM Policy' be sure to put that code exactly in the way he has it in the blog. Don't be neurotic and change the date (like i did) it won't work. 
**Refer to the syntax here for command line & your BAT files, it's cleaner and more efficient. 
**I decided to create a Windows Environment Variable according to the Amazon Help Docs rather than embedding them into the command. 

Amazon Help Documentation:
**I went through these Tasks/Steps (1-4) rather closely and carefully.
**Including having to install Java because it's doesn't come installed on the Micro Instance.
**Final step asks you to test by typing the command C:\> ec2-describe-regions This broke for me because the IAM user I set up doesn't have the credential to do this. However, using CMD to start/Stop the instance worked wonderfully. 
**I did reset the system clock to be in the Eastern timezone (same as the Amazon data center where it lives. 

Remember: I'm in a different timezone than my server, So it's scheduled to turn off from 11:30pm - 5:30am

Remember: I'm in a different timezone than my server, So it's scheduled to turn off from 11:30pm - 5:30am

The Final Step was to set up three simple Windows Scheduled Tasks. And Boom. You've got you cost saving measure on the books. No go ask for a big raise.