Saturday, September 25, 2010

Creating an image of a running EC2 instance

Prerequisites
  1. AWS User ID
  2. AWS Key ID
  3. AWS Secret Key
  4. x.509 Key pair (cert and private key)
All of this can be obtained from the AWS account info page here. Note AWS does not store the private key of your x.509 key pair, if you do not have you will need to create a new key pair.

Creating the bundle
  1. Upload your x.509 cert and private key to your running ec2 instance.
  2. scp PATH_TO_KEYS/{cert,pk}-*.pem root@AWS_INSTANCE:/mnt
  3. Log into your ec2 instance
  4. ssh -i YOURKEY.pem root@AWS_INSTANCE
  5. Set up some environment variables to make the processes a little easier. Set arch to either i386 or x86_64 depending if you have a 64 bit or 23 bit instance. If your not sure which to choose you can check here
  6. # export AWS_USER_ID=YOUR_AWS_USER_ID
    # export AWS_ACCESS_KEY_ID=YOUR_KEY_ID
    # export AWS_SECRET_ACCESS_KEY=YOUR_SECRET_KEY
    # export arch=i386
  7. Create bundle
  8. ec2-bundle-vol -r $arch -d /mnt/ -p $prefix -u $AWS_USER_ID -k /mnt/pk-*.pem -c /mnt/cert-*.pem -s 10240 -e /mnt,/root/.ssh
  9. Upload bundle
  10. ec2-upload-bundle -b $bucket -m /mnt/$prefix.manifest.xml -a $AWS_ACCESS_KEY_ID -s $AWS_SECRET_ACCESS_KEY
  11. Register bundle
  12. ec2-register --name "$bucket/$prefix" $bucket/$prefix.manifest.xml