Global Constant
Steve Nay's ramblings

Building up an AMI from Ubuntu 10.04 LTS

Now that I’ve gotten the hang on Amazon EC2, I’m ready to start building my actual stem cell server. I’m starting from the Ubuntu 10.04 LTS image provided by Canonical (ami-a403f7cd). It’s a bare-bones server instance that doesn’t even have Apache on it yet, although it does have Python.

Setting up the Server

I’m going to need the EC2 AMI tools, which requires allowing the Multiverse repository, so I added these to lines to my /etc/apt/sources.list.d/multiverse.list first:

deb karmic multiverse
deb-src karmic main

Here are the packages I installed (after running apt-get update):


These packages may also be useful but aren’t strictly necessary at this point:


I ran apt-get upgrade as well. This presented me with a couple prompts (one from GRUB), which I had to get through. And since it included a kernel update, I restarted the machine.

Next, I added the necessary Python directives to my /etc/apache2/sites-available/default file, as I documented earlier.

I added a simple page in /var/www to handle CGI requests. One thing that confused me for a long while is that can’t just be any old Python script; it has to be a CGI request handler. Here’s a simple example:

def index(req):
  return "Hello, world!"

Creating and Registering the AMI

The next step is creating an AMI from this image and saving that to S3. I’m using this tutorial from Amazon as my guide.

There are three basic steps:

  1. Bundle the volume First, I got the X509 certificate and my private key and put them on /mnt. I also got my account number handy (available from the same place in the AWS console as the public/private keys). Then I ran these commands:
    sudo mkdir /mnt/image
    sudo ec2-bundle-vol -k PrivateKey.pem -c X509Cert.pem -u 000000000000 -d /mnt/image
    Replace the 000000000000 with your account ID. After several minutes, that created the AMI bundle in /mnt/image.
  2. Upload the bundle to S3 I used this command:
    ec2-upload-bundle -b cs462-machines/snay2-test1 -m /mnt/image/image.manifest.xml -a <access key> -s <secret key>
    Replace the snay2-test1 with your own folder name inside the bucket.
  3. Register the AMI I have my dev machine set up such that I don't have to pass the keys along on the command line (see this post for how I did that). But if you don't have it set up that way or if you want to run the command from your EC2 instance directly, that's possible too. Here is the command:
    ec2-register cs462-machines/snay2-test1/image.manifest.xml --K PrivateKey.pem -C X509Cert.pem
    Replace the snay2-test1 with your own folder name inside the bucket. After a second, that came back with the AMI name. We're done!

EDIT: Here is a detailed tutorial from the Ubuntu community on the AMI tools and other necessary EC2 things.

EDIT: Revised the last portion of the post to reflect the three basic steps of persisting an AMI.