Starting a group of EC2 instances with a single command

I’m working on a project that involves a number of Amazon EC2 instances. To keep costs under control, I decided it would be worthwhile to write a script to start and stop my instances in bulk.

I started with the online documentation for AWS:

http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/index.html?SettingUp_CommandLine.html

I found it’s pretty easy to do. Once you install the Amazon command line tools and get your environment variables set up, it’s pretty simple to start and stop your instances. Here’s a quick and dirty shell script I wrote:


#!/bin/bash

ec_suite_start() {
echo "Starting ec_suite instances"

# Magento 01
ec2-start-instances i-7fe7e71c

# DB01
ec2-start-instances i-73e8e810
}

ec_suite_stop() {
echo "Stopping ec_suite instances"

# Magento 01
ec2-stop-instances i-7fe7e71c

# DB01
ec2-stop-instances i-73e8e810
}

case $1 in
start)
ec_suite_start
;;
stop)
ec_suite_stop
;;
*)
echo "Usage: control.sh {start|stop}"
;;
esac

Next up, I’m going to try to launch and configure a web server with Chef. Exciting!

Related posts:

{ 1 comment to read ... please submit second! }

  1. AWS stuff is a lot of fun to play with. I’ll be interested to see how Chef works out. I haven’t yet found an excuse to play with it.

{ 0 Pingbacks/Trackbacks }

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>