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

Comments:

Very helpful.

Step 9 is now completed by going to AMIs in the AWS control panel and adding the /bucketname/image.manifest.xml path at the end.

ec2-register was not available in the image that I fired up.

Also for those of you tearing their hair out over how to use S3 as I was, you need a third party tool as S3 offers nothing more than an API, so try s3browser.com.

cb
--

Posted by Chris Bell on June 11, 2009 at 05:28 PM CEST #

Hi James,

This was just the information I was looking for... and just a bit late :)

I struggled with ubuntu's ec2-vmbuilder and with EU/US buckets and stuff like that.

This information is straight to the point and very useful.

One small question thought:
I noticed that after completing all steps, when launching a new instance, I can't choose the instance type (small/high-cpu/medium) anymore. Also in the ami browser no details (architecture/kernel/platform) show up. Do you know of a way to fix this? Since I'm basing my AMI off an AMI that did support instance-type selection and did not change the kernel or ramdisk, I think it's strange this feature disappears by just cloning. perhaps I need to add some stuff to the manifest?

Posted by Mathijs Kwik on June 24, 2009 at 02:20 AM CEST #

Hi Mathijs,

I tried to recreate this with one of my custom AMIs, but couldn't. The only thing I can think of that might affect this parameter is that AWS has set limits for certain platforms, etc. I promise to look into this. If you can, please send me an update on your progress. Maybe we can solve the problem together.
--James

Posted by James on June 24, 2009 at 04:09 PM CEST #

Post a Comment:
Comments are closed for this entry.

Calendar

Feeds

Search

Links

Navigation

Referrers