Since I’ve started using the EC2 service, I am aware of the hourly costs if my server is running overnight if I’m in the process of configuring it. Subsequently I’ve discovered I can actually back it up as a private AMI instance onto S3 and then restart it later when required.
In order to accomplish this, you would need 2 sets of information: your set of private key and certificate which is used to instantiate the EC2 server; this would need to be copied onto the running instance using scp; and the EC2 AMI tools installed. The AMI tools is required to bundle and upload the final image onto S3.
Once the above is in place, just issue the following command within the instance console:
ec2-bundle-vol -d /mnt -k /root/PrivateKey.pem --cert /root/Certificate.pem -u 012345678901 -a -e /var/mysql,/var/log/
The ec2-bundle-vol command is from the AMI tools. The -d option specifies where the image segments go; the -k switch specifies the private key used to create the AMI; the certificate is from your own amazon certificate and the -u identifier is your amazon account ID. The -a switch specifies to include all directories and the -e switch specifies a list of directories to exclude from the process; this can be used to exclude the directories such as where your certificate and keys are stored as well as log folders to save space on the resulting image.
Once it starts running, the command will generate a flatfile of the entire AMI onto /mnt and subsequently it breaks it down into various segments of fixed sizes within the /mnt directory. Once the process is complete an ‘image.manifest.xml’ will also be generated in the /mnt directory. This specifies the segments needed to recreate the AMI.
To upload the AMI into S3 you would need to create a new bucket first. Then use the ec2-upload-bundle command as follows:
ec2-upload-bundle -b yourbucketname -m /mnt/image.manifest.xml -a your_s3_access_key -s your_s3_secret_access_key
You should see the name of each image segment which has been uploaded into the S3 bucket successfully showing up.
Once that is complete, first check to make sure that all the segments and the manifest are in the bucket. Then you can terminate the AMI and log into your amazon console in the browser to register the AMI.
Navigate to the Amazon EC2 Management Console > AMIS > Register new AMI. Specify the bucket name followed by the manifest to register your AMI:
yourbucketname/image.manifest.xml
If the above all goes well you should see your AMI registered and should be able to launch it by right clicking on it and selecting ‘launch’.



