Shell scripting EC2 for fun and profit
Lately I’ve been doing some work with creating ad-hoc clusters of EC2 machines. My ultimate goal is to create a simple way to spin up a cluster of EC2 machines for use with Bryan Lewis’s very cool doRedis backend for the R foreach package. But that’s a whole other post. What I was scratching my head about today was that I’d really just like to, with a single command, spin up an EC2 instance, wait for it to come up, and then ssh into it. I do this iteration about 20 times a day when I’m testing things, so it seemed to make sense to shell script it.
To do this, one needs the EC2 command line tools installed on your workstation. In Ubuntu that’s as easy as `sudo apt-get ec2-api-tools`
So here’s a short shell script to spin up an instance, wait 30 seconds, then connect:
If you’re reading this through an RSS reader, you can see the script over at github.
Obviously you’ll need to change the parameters at the top of the script to suit your needs. But since this was a bit of a pain in the donkey hole for me to figure out, I thought I would share.
If you want to help out, I’d love you to enlighten me on how to have the script figure out if an instance has finished booting so I could eliminate the sleep step.