LAMP on EC2 - Part 10: Generating a Custom AMI
Wednesday, March 4, 2009 at 8:33AM So in our last post, we created scripts that would take snapshots of our persistent volume. So that covers our persistent datastore. But what about the changes we have made to our Linux image. In the event that the instance goes down, we would loose any configuration changes made to date. So we will create our own private AMI of our current Linux instance state. In the event of a failure or even to spawn multiple images, we can use this custom AMI to quickly restore our state.
This post is part of a series of posts detailing the steps required to host a LAMP installation on Amazon's Elastic Computing Cloud. Steps in this post may depend on actions taken in previous posts. Amazon's Web Cloud Services are a pay-as-you-go service so please realize anything you do may result in charges to your Amazon account.
To do this, first shut down MySQL and Apache and unmount your persistent store using the following commands:
/etc/rc.d/init.c/mysql stop
/etc/rc.d/init.c/httpd stop
umount /persistent
Go to your AWS Management Console and retrieve your Owner ID from the running instance. Copy that and paste it within the following command, which creates the new AMI:
ec2-bundle-vol --fstab /etc/fstab \
-c /home/ec2/certs/[certificate] \
-k /home/ec2/certs/[private key] \
-u [Owner ID]
This will create the image in the /tmp directory, but that image still needs to be uploaded. Upload it using the following command:
ec2-upload-bundle -b [bucket name] \
-m /tmp/image.manifest.xml \
-a [Access Key ID] \
-s [Secret Access Key]
where the bucket name is a globally unique identifier. It can be the name of an bucket you already use or a new one, in which case the bucket will be created (if the name is available).
You will need to register this new AMI with AWS Management Console by going to the AMIs and clicking the Register New AMI. The AMI manifest path that it will ask for is your bucket's name followed by /image.manifest.xml. The AWS Management Console should add your AMI to the list of public ones (it will be marked "private"). If you don't see it right away, you can do a search for a substring within the name of your bucket.

