Reputation: 15219
I am using Boto to create an AMI of one of my EC2 boxes, and then I would like to spin up more boxes with that AMI, but the run_instances
command is barking that my AMI is not available yet.
How can I use boto to query aws to find out when my ami is ready?
The EC2 connection supports a method to get_image
But the Image does not have any sort of status attribute
Upvotes: 4
Views: 5549
Reputation: 377
I can write a simple function using boto3
def check_ami_exists(ami_id, region):
client = boto3.client('ec2', region_name = region)
response = client.describe_images()
for image in response['Images']:
if ami_id == image['ImageId']:
return True
return False
Upvotes: 0
Reputation: 117
I used the above method but it took a little while for me to figure it out. Not a python person but here is what I did. Hope it helps someone.
#EC2 Connection
conn = boto.ec2.connect()
image_status = conn.get_all_images(image_ids='ami-XXX')[0]
image_state = image_status.state
print image_state
Upvotes: -1
Reputation: 5118
In addition to "pending" and "available" there is also the "failed" state. This is the full set of AMI states available.
Upvotes: 1