Friday, April 18, 2014

Cleaning Up Your Amazon EBS-Backed AMI

Deregistering Your AMI

You can deregister an AMI when you have finished using it. After you deregister an AMI, you can't use it to launch new instances.
When you deregister an AMI, it doesn't affect any instances that you've already launched from the AMI. You'll continue to incur usage costs for these instances. Therefore, if you are finished with these instances, you should terminate them.
The procedure that you'll use to clean up your AMI depends on whether it is backed by Amazon EBS or instance store.

Cleaning Up Your Amazon EBS-Backed AMI

When you deregister an Amazon EBS-backed AMI, it doesn't affect the snapshot that we created when you created the AMI. You'll continue to incur usage costs for this snapshot in Amazon EBS. Therefore, if you are finished with the snapshot, you should delete it.
The following diagram illustrates the process for cleaning up your Amazon EBS-backed AMI.
Process to clean up your Amazon EBS-backed AMI
To clean up your Amazon EBS-backed AMI
  1. Open the Amazon EC2 console.
  2. In the navigation pane, click AMIs. Select the AMI, click Actions, and then click Deregister. When prompted for confirmation, click Continue.
    The AMI status is now unavailable.
  3. In the navigation pane, click Snapshots. Select the snapshot and click Delete Snapshot. When prompted for confirmation, click Yes, Delete.
  4. (Optional) If you are finished with an instance that you launched from the AMI, terminate it. In the navigation pane, click Instances. Select the instance, click Actions, and then click Terminate. When prompted for confirmation, click Yes, Terminate.

Cleaning Up Your Instance Store-Backed AMI

When you deregister an instance store-backed AMI, it doesn't affect the files that you uploaded to Amazon S3 when you created the AMI. You'll continue to incur usage costs for these files in Amazon S3. Therefore, if you are finished with these files, you should delete them.
The following diagram illustrates the process for cleaning up your instance store-backed AMI.
Process to clean up your instance store-backed AMI
To clean up your instance store-backed AMI
  1. Deregister the AMI using the ec2-deregister command as follows.
    ec2-deregister ami_id
    The AMI status is now unavailable.
  2. Delete the bundle using the ec2-delete-bundle command as follows.
    ec2-delete-bundle -b myawsbucket/myami -a your_access_key_id -s your_secret_access_key -p image
  3. (Optional) If you are finished with an instance that you launched from the AMI, you can terminate it using the ec2-terminate-instances command as follows.
    ec2-terminate-instances instance_id
  4. (Optional) If you are finished with the Amazon S3 bucket that you uploaded the bundle to, you can delete the bucket. To delete an Amazon S3 bucket, open the Amazon S3 console, select the bucket, click Actions, and then click Delete.