What are waiters, and why use them instead of `sleep` loops?
IntermediateConceptboto3 & AWS automation
Answer
Waiters poll a describe call until a resource reaches a state, with a built-in delay and max attempts, and raise WaiterError on failure states or timeout.
ec2.start_instances(InstanceIds=[iid])
ec2.get_waiter("instance_running").wait(InstanceIds=[iid],
WaiterConfig={"Delay": 10, "MaxAttempts": 30})
Other common ones: instance_stopped, snapshot_completed, db_instance_available, stack_create_complete, object_exists. They encode failure states (for example a stack that rolled back) that a homemade loop often forgets.
More on boto3 & AWS automation
What is the difference between a boto3 Session, client and resource?BeginnerHow does boto3 find credentials?BeginnerHow does boto3 decide the region, and what is the gotcha with `AWS_REGION`?AdvancedWhy do you need paginators, and how do you use them?BeginnerWhat is JMESPath `search()` on paginators?AdvancedHow do you handle errors from boto3?Beginner