Bundling an AMI
A root file system image needs to be bundled as an AMI in order to be used with the Amazon EC2 service. The bundling process first compresses the image to minimize bandwidth usage and storage requirements. The compressed image is then encrypted and signed to ensure confidentiality of the data, and authentication against the creator. The encrypted image is finally split into manageable parts for upload. A manifest file is created containing a list of the image parts with their checksums. This chapter provides an overview of the AMI tools that automate this process and some examples of their use.
The AMI tools are three command-line utilities:
-
ec2-bundle-image bundles an existing AMI
-
ec2-bundle-vol creates an AMI from an existing machine or installed volume
-
ec2-upload-bundle uploads a bundled AMI to S3 storage
The AMI tools are packaged as an RPM suitable for running on Fedora Core 3/4 with Ruby 1.8.2 (or greater) installed. On Fedora Core 4 Ruby can be installed by following the steps below. You will need root privileges to install the software. You can find the AMI tools RPM from our public S3 downloads bucket.
First install Ruby using the yum package manager.
#
yum install ruby
Install the AMI tools RPM.
#
rpm -i ec2-ami-tools-
x.x-xxxx
.i386.rpm
The AMI tools libraries install under
/usr/lib/site_ruby
. Ruby should pick up
this path automatically, but if you see a load error when
running one of the AMI utilities, it may be because Ruby isn't
looking there. To fix this, add /usr/lib/site_ruby
to Ruby's library path, which is set in the
RUBYLIB
environment variable.
The manual describing the operation of each utility can be
displayed by invoking it with the
--manual
parameter. For example:
#
ec2-bundle-image --manual
Invoking a utility with the --help
parameter
displays a summary and list of command line parameters. For
example:
#
ec2-bundle-image --help
Once a machine image has been created it must be bundled as an AMI for use with Amazon EC2, as follows. Use ec2-bundle-image to bundle an image that you have prepared in a loopback file, as described in the previous section.
#
ec2-bundle-image -i my-image.img -k
pk-HKZYKTAIG2ECMXYIBH3HXV4ZBZQ55CLO.pem
-ccert-HKZYKTAIG2ECMXYIBH3HXV4ZBZQ55CLO.pem
-u12345678
This will create the bundle files:
image.part.00 image.part.01 ... image.part.NN image.manifest.xml
Alternatively an AMI could be created by snapshotting the local machine root file system and bundling it all at once by using ec2-bundle-vol. (note: you will need to have root privileges to do this and SELinux must be disabled). Use ec2-bundle-vol to re-bundle a (modified) running instance of an existing AMI, as described in the previous section.
#
ec2-bundle-vol -k
pk-HKZYKTAIG2ECMXYIBH3HXV4ZBZQ55CLO.pem
-ccert-HKZYKTAIG2ECMXYIBH3HXV4ZBZQ55CLO.pem
-s 1000 -u 495219933132
As with ec2-bundle-image, ec2-bundle-vol will create image parts files and a manifest file.
Note | |
---|---|
If selinux is enabled when ec2-bundle-vol is run, the filesystem creation step may fail. Selinux should be disabled while this is done. |
The bundled AMI needs to be uploaded for storage in Amazon S3 before it can be accessed by Amazon EC2. Use ec2-upload-bundle to upload the bundled AMI that you created as described above. S3 stores data objects in buckets, which are similar in concept to directories. Buckets must have globally unique names. The ec2-upload-bundle utility will upload the bundled AMI to a specified bucket. If the specified bucket does not exist it will be created. However, if the specified bucket already exists, and belongs to another user, then ec2-upload-bundle will fail.
#
ec2-upload-bundle -b
my-bucket
-m image.manifest.xml -amy-aws-access-key-id
-smy-secret-key-id
The AMI manifest file and all image parts are uploaded to S3. The manifest file is encrypted with the Amazon EC2 public key before being uploaded.