Automating AWS instance shutdown and start-up

 

I love AWS and we recently had a very nice summit in Bangalore which I was able to attend. Once of the immediate things that caught my attention was that there were a lot of people who attended. The overall majority of them were fairly new to AWS while the rest were experts. There really was no midway crowd like myself. Once of the important things I got to learn from the summit was that I was overpaying for my instance. While I knew this all along I never got around to doing something about it. Obviously one of the first things that came to mind was to shutdown instances which were not being used. What this means is that I had the instance running 24/7 even though it was a developer instance and we never really used it after 7 PM IST. I wanted to automate the process and tried a number of tools such as EC2 scheduler and AWS alarams but they didn’t quite fit exactly where I wanted them.

So I decided to take matters into my own hands. The best way to do this I figured was to use the Command line tools. Why? It was just easier. A few environment variables and then all I needed to do was create batch files on my windows machine. The below link shows you how to configure and use AWS Command line tools to call the API and pass commands to your EC2 instance. Its not that difficult for those who have experience with the windows OS or scripting in cmd or unix etc.

http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/InstallEC2CommandLineTools.html

I would have loved to post the screenshot but I didn’t take any. But to summarize the entire article here are the main steps.

  • Download and install the latest version of Java
  • Download and install the AWS command line tools from here.
  • Set environment variable for the Java