question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ec2.Waiter.ImageAvailable doesn't wait till image state is "available"

See original GitHub issue

ec2.Waiter.ImageAvailable doesn’t wait till image state is “available”

for image in images['Images']:
    print("building image for %s" % image['Name'])
    instance = buildinstance(SharedServicesCreds, image)
    instance[0].wait_until_running()
    pp.pprint(instance[0].launch_time)
    newimage = instance[0].create_image(Name=image['Name'])
    pp.pprint(newimage.state)
    # wait_until_exits only checks that the image exists not that it is in state available
    newimage.wait_until_exists()
    waiter = sharedservicesec2client.get_waiter('image_available')
    waiter.wait(ImageIds=[ newimage.image_id ])
    pp.pprint(newimage.state)

building image for MY-RHEL7-INSTANCE datetime.datetime(2017, 8, 18, 17, 24, 43, tzinfo=tzutc()) ‘pending’ ‘pending’

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

7reactions
progre55commented, Feb 10, 2018

I’ll just leave it here… not sure if this has been added recently, or always been there, but instead of the empty .wait_until_exists(), you can pass in a filter to it:

image.wait_until_exists(Filters=[{'Name': 'state', 'Values': ['available']}])

and it will return only after your image state has changed to available.

1reaction
joguSDcommented, Aug 29, 2017

My previous statement was only half correct, my apologies. While it is true that the waiter accessed via a boto3 resource will not refresh the resource, it does clear the cached data. This means that the next attempt to access an attribute on the resource will force it to be hydrated again. Thus the difference in behavior here ultimately comes down to accessing the waiter via a boto3.Resource or directly from botocore. Adding the waiter you’re using to the resource definition may be one route to make the behavior consistent. As a workaround for now you could manually refresh your resource after the waiter has ended.

We need to add the image_available waiter to the image resource.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AWS boto3 image waiter is not working properly
1. We need more detail about what "doesn't work" means. Is the image available, but it's in pending state? · Image state is...
Read more >
image-available — AWS CLI 1.27.29 Command Reference
Wait until JMESPath query Images[].State returns available for all elements when polling with describe-images .
Read more >
EC2 — Boto3 Docs 1.26.32 documentation - AWS
Amazon Elastic Block Store (Amazon EBS) provides block level storage volumes for use with EC2 instances. EBS volumes are highly available and reliable ......
Read more >
Working with EC2 Instances using Boto3 in Python
MaxCount – maximum number of EC2 instances to launch; ImageId – the Amazon Machine Image, which is used to launch your EC2 instance...
Read more >
Amazon AMI - Builders | Packer - HashiCorp Developer
Works similarly to the chroot builder but does not require running in AWS. ... easier to use and Amazon generally recommends EBS-backed images...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found