Managing and Sharing AMIs

Image management is an advanced subject that will be discussed in detail in Chapter 6. For the time being, we will merely summarize the API operations that are available to manage your AMIs in EC2.

Register an AMI

The RegisterImage operation outlined in Table 5-24 registers an AMI to make it available in the EC2 environment. Before it can be registered, the AMI must first be bundled into image files and uploaded to S3 with a manifest XML file.

Table 5-24. RegisterImage request parameters

Parameter NameValueRequired?
ActionRegisterImageYes
ImageLocationThe full path to the image manifest file stored in S3, including the bucket name and object keyYes

Here is an XML document returned by the operation. It is very simple, containing only the element imageId which contains a unique identifier for the AMI that has been registered.

<RegisterImageResponse xmlns='http://ec2.amazonaws.com/doc/2007-08-29/'>
  <imageId>ami-d39075ba</imageId>
</RegisterImageResponse>

Example 5-17 defines a method to register an AMI that is described by an image manifest file stored in S3. The method returns the unique identifier value assigned to the registered AMI.

Example 5-17. Register an image: EC2.rb

def register_image(image_location) parameters = build_query_params(API_VERSION, SIGNATURE_VERSION, { 'Action' => 'RegisterImage', 'ImageLocation' => image_location, }) response = do_query(HTTP_METHOD, ENDPOINT_URI, parameters) xml_doc = REXML::Document.new(response.body) return xml_doc.elements['//imageId'].text ...

Get Programming Amazon Web Services now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.