Interview Prep/Python for DevOps/AWS automation with boto3

A script must create an S3 bucket if it does not exist, and it runs in parallel CI jobs. How do you make it race-safe?

AdvancedScenarioAWS automation with boto3
Answer

Situation read → Check-then-create races between jobs.

What I'd do →

  1. Skip the check; call create_bucket and treat BucketAlreadyOwnedByYou as success.
  2. Treat BucketAlreadyExists (someone else owns the name globally) as a real error.
  3. Pass CreateBucketConfiguration={"LocationConstraint": region} outside us-east-1.
  4. Apply settings (encryption, public access block, versioning) idempotently after creation.
  5. Better: create buckets once in Terraform, not in CI jobs.

Why → EAFP avoids the time-of-check/time-of-use race.

Interview tip → Know the two error codes and what each means.

All Python for DevOps questions Roadmap: Python for automation

More on AWS automation with boto3