Interview Prep/Python for DevOps/boto3 & AWS automation

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.

All Python for DevOps questions Roadmap: Python for automation

More on boto3 & AWS automation