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:

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:

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:

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:

Replace the 000000000000 with your account ID.

After several minutes, that created the AMI bundle in /mnt/image.

<li><strong>Upload the bundle to S3</strong>

I used this command:

Replace the snay2-test1 with your own folder name inside the bucket.

<li><strong>Register the AMI</strong>

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:

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.