Launch an EC2 instance with boto3 and wait until it passes status checks, using a waiter.

IntermediateHands-onPython for DevOps
Answer
import boto3

ec2 = boto3.client("ec2")
resp = ec2.run_instances(ImageId="ami-0abcdef1234567890", InstanceType="t3.micro",
                         MinCount=1, MaxCount=1)
iid = resp["Instances"][0]["InstanceId"]

ec2.get_waiter("instance_status_ok").wait(
    InstanceIds=[iid], WaiterConfig={"Delay": 15, "MaxAttempts": 40})
print(f"{iid} passed status checks")

Key trick → Waiters handle polling and timeouts for you. instance_running only means the state is running; instance_status_ok waits for the system and instance status checks to pass.

All Real-World Interview questions Roadmap: Interview readiness

More on Python for DevOps