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!