(cross posted to boto-users)
Given an image ID, how can I delete it using boto?
Advertisement
Answer
You use the deregister() API.
There are a few ways of getting the image id (i.e. you can list all images and search their properties, etc)
Here is a code fragment which will delete one of your existing AMIs (assuming it’s in the EU region)
JavaScript
x
13
13
1
connection = boto.ec2.connect_to_region('eu-west-1',
2
aws_access_key_id='yourkey',
3
aws_secret_access_key='yoursecret',
4
proxy=yourProxy,
5
proxy_port=yourProxyPort)
6
7
8
# This is a way of fetching the image object for an AMI, when you know the AMI id
9
# Since we specify a single image (using the AMI id) we get a list containing a single image
10
# You could add error checking and so forth ... but you get the idea
11
images = connection.get_all_images(image_ids=['ami-cf86xxxx'])
12
images[0].deregister()
13
(edit): and in fact having looked at the online documentation for 2.0, there is another way.
Having determined the image ID, you can use the deregister_image(image_id) method of boto.ec2.connection … which amounts to the same thing I guess.