Cleaning up EC2 Images, AMIs, and Instances

items>Cleaning up EC2 Images, AMIs, and Instances
This document clarifies the steps required for cleaning up images, AMIs, and instances. It builds on the "Cleaning Up" section of the Getting Started Guide.


Submitted By: Attila@AWS
AWS Products Used: Amazon EC2
Created On: February 8, 2007 11:34 AM GMT
Last Updated: September 21, 2008 10:08 PM GMT


Deleting an image bundle from Amazon S3 will not automatically de-register associated AMIs. It is important to de-register all associated AMIs if an image is removed from Amazon S3.  Similarly removing an image bundle from Amazon S3 or de-registering associated AMIs will not terminate running instances of those AMIs.

The following points are important to remember when dealing with images, AMIs, and instances in Amazon EC2:
  • An image is bundled and stored in Amazon S3--it's just bits.
  • An image can be registered as an AMI with Amazon EC2 by telling EC2 where it is stored in Amazon S3. The registration process returns an AMI ID that is used to refer to the AMI.
  • An image can be registered multiple times. Each registration returns a new AMI ID.
  • An instance is a virtual machine that is launched with a given AMI.

Recommended Cleanup Process

Follow these three steps to completely clean up an image bundle, associated AMIs, and instances:
  1. All instances of all AMIs registered using the image bundle should be terminated.
  2. All AMIs registered using the image bundle must be de-registered using ec2-deregister.
  3. The image bundle should be deleted from Amazon S3 using ec2-delete-bundle or any other tool that can delete files in Amazon S3.

Instances can be terminated by using the ec2-terminate-instances command-line tool that is part of the API Tools, or by calling the TerminateInstances API. Although instances of a de-registered AMI can be left running, new instances of that AMI cannot be launched.

An AMI can be de-registered by using the ec2-deregister command-line tool, also part of the API Tools, or by calling the DeregisterImage API.

The image bundle in Amazon S3 can be cleaned up using ec2-delete-bundle command-line tool which is part of the AMI Tools. Please note that the AMI Tools are different from the command-line API Tools. Any other tool to delete files from Amazon S3 can also be used.

Please also review the latest Release Notes for any known issues that may exist in this area.

©2017, Amazon Web Services, Inc. or its affiliates. All rights reserved.