Working with Ubuntu on Amazon EC2


I tried quite hard to make Amazon's default Linux image work for my project, but eventually ran into so many issues building software for it that I reverted to Ubuntu on EC2.  Here are some notes based on my experience.

Most likely you'll want to:
- launch an existing stock Ubuntu image
- modify it to run your service (which starts on reboot)
- snapshot the now-configured instance into a new AMI (Amazon Machine Image) so that you can launch more of them.

This page: https://help.ubuntu.com/community/EC2StartersGuide describes how to get an instance running with the official Ubuntu EC2 images.  I chose 9.10 Karmic since it's nice and stable at this point, you might prefer to use a later version.

Next, configure the running instance until your service is up and running and happily starts itself on a reboot.  I used a pretty atypical setup with lighttpd, fastcgi and a custom C binary, but you can do anything at this point :-)

Now, to snapshot the running service, I found that all the existing tutorials on the web were misleading / out of date / wrong!

First up, the Ubuntu EC2 commandline tools can be installed on the instance with
sudo apt-get install ec2-api-tools
(This also installs a Java runtime)

But, I found that some of the required tools are missing in this distro, so *also* had to install the official Amazon tools from http://aws.amazon.com/developertools/368 

wget "http://s3.amazonaws.com/ec2-downloads/ec2-ami-tools.zip"
The amazon tools need ruby, so
sudo apt-get install ruby
and that ruby distro is missing the required OpenSSL support
the error message:
/home/ubuntu/aws/ec2-ami-tools-1.3-57676/lib/ec2/amitools/crypto.rb:13:in `require': no such file to load -- openssl (LoadError)
from /home/ubuntu/aws/ec2-ami-tools-1.3-57676/lib/ec2/amitools/crypto.rb:13
...
so you also need
sudo apt-get install libruby1.8-extras
which will get it.  The amazon tools now run OK - phew :-)

Now I was able to loosely follow the instructions on http://alestic.com/2009/06/ec2-ami-bundle to bundle my running image.

deltas from the instructions on that page:
  the ec2-register command does not take a --name parameter


(Exact commands I issued below)
sudo -E bin/ec2-bundle-vol -r i386 -d /mnt -p MY_PREFIX -u MY_USER_ID -k /mnt/pk-*.pem -c /mnt/cert-*.pem -s 10240 -e /mnt,/root/.ssh,/home/ubuntu/.ssh

sudo -E bin/ec2-upload-bundle -b MY_BUNDLE -m /mnt/MY_PREFIX.manifest.xml -a MY_ACCOUNT -s MY_SECRET
Comments