Friday, August 25, 2006

Sandboxing Amazon EC2

Here's something cool I'd like to share--if you've gotten into the Amazon EC2 beta and want to repeatedly test your images (like we've been doing), it's helpful to automate the process. Well--that's what we've done with a little bash scripting. We've created two scripts: new_instance and temp_instance. The new_instance script does all the legwork to ready a server and even logs you in when it is available. It looks like this:

Bravo:~/Projects/ec2 jonathan$ ./new_instance Starting a fedora core base AMI. Instance is i-e17b9e88. Polling server status (ec2-describe-instances i-e17b9e88) ................................................................. The server is available at domU-12-31-33-00-01-66.usma1.compute.amazonaws.com. Warning: Permanently added 'domu-12-31-33-00-01-66.usma1.compute.amazonaws.com,216.182.228.100' (RSA) to the list of known hosts. __| __|_ ) _| ( / ___|\___|___| Welcome to an EC2 Public Image :-) [root@domu-12-31-33-00-01-66 ~]# logout Connection to domU-12-31-33-00-01-66.usma1.compute.amazonaws.com closed. Terminate with: ec2-terminate-instances i-e17b9e88
The temp_instance script works identically, but terminates the running instance on logout, rather than just echoing the termination command. To get the scripts to work, you'll want a directory layout like: Bravo:~/Projects/ec2 jonathan$ ls -l -rwxr-xr-x 1 jonathan jonathan 689 Aug 24 23:17 cert-PSQ...US576UB.pem drwxrwxrwx 4 jonathan jonathan 136 Aug 23 06:17 ec2-api-tools-1.2-5502 -rw------- 1 jonathan jonathan 1671 Aug 24 23:24 id_rsa-gsg-keypair -rwxr-xr-x 1 jonathan jonathan 1090 Aug 25 01:10 new_instance -rwxr-xr-x 1 jonathan jonathan 721 Aug 24 23:17 pk-PSQ...576UB.pem -rwxr-xr-x 1 jonathan jonathan 1113 Aug 25 01:10 temp_instance You should have this or something like it already if you've followed the getting started docs. There is one other step--edit the temp_instance and new_instance files and make the pk-*.pem and cert-*.pem filenames match those generated for your usage. Any comments are appreciated.

1 comments:

Daniel said...

Thanks! This is really useful.