JamesBranam's Blog

Tuesday Jun 02, 2009

AWS Experience Part 6: Creating a Custom AMI

Hi all,

Here is another installment on working in the cloud, the AWS cloud that is. Today's topic: creating a custom AMI. This may sound like as easy task. And it would have been, had AWS documentation been up to scratch. I spent lots of time messing around with this, and I finally got it to work. Here's how:

  1. Launch an exiting image (I chose a Fedora 8 image). Modify the /var/www/html/index.html file to something else (thus making it "your unique AMI). I went one step further: I installed JDK 6 and MySQL on mi AMI for use at a later date.
  2. Now you have to upload your private key and x509 certificate to the AMI. Here's how to do this in the terminal:
    scp -i ~/.ssh/<yourkeypair.pem> ~/.ec2/<pk-whatever.pem> ~/.ec2/<cert-whatever.pem> root@your-public-DNS:/mnt.
    The private key and x-509 certificate should be uploaded to the mnt directory to prevent them from being bundled with the new AMI.
  3. When this has been done, log in to your AMI to check if it is there.
  4. While you're logged in to your virtual server, you can perform the next step of the process. (The reason I am even mentioning this is that AWS didn't mention it). Type the following command
    ec2-bundle-vol -d /mnt -k /mnt/<personalkey.pem> -c /mnt/<cert.pem> -u <AWS-acct-no> -r i386 -p sampleimage
  5. Get a cup of coffee as this will take a while.
  6. Type the following to check if the AMI image is indeed there where it should be:
    ls -l /mnt/sampleimage.*
  7. Upload your bundle to AWS S3 Storage. (Make sure that you sign up for S3 before you do this.) To do, type:
    ec2-upload-bundle -b <S3-bucket-name> -m /mnt/sampleimage.manifest.xml -a <AWS-access-key-id> -s  <AWS-secret-access-key> --location EU
    Note: Remember to upload to an S3 bucket in correct region. Also: if the bucket does not exit, it will be created for you. (I've used a European bucket as an example.)
  8. Now we get to register the AMI with AWS. Type the following:
    ec2-register <bucket-name>/sampleimage.manifest.xml --region EU-WEST-1

    AWS returns the new AMI ID (in my case ami-2faf875b).
  9. Go to the AMIs panel of the your AWS Management Console and do a search for part of your AMI. It's there and ready for use! (You can see mine in the screenshot at the top of this blog entry.)
I hope that this information will save a lot of people a lot of time. I have just spent hours scouring AWS documentation, forums and google search results to get this far. The most useful of these: Google by far. Amazon documentation left out key information and variables. Yuck!

Cheers!

--James

Calendar

Feeds

Search

Links

Navigation

Referrers