Skip to content
Latchkey

aws s3api create-bucket: Create an S3 Bucket in CI

Create a new S3 bucket, with the region quirk that trips up every first-timer.

aws s3api create-bucket provisions a bucket. Outside us-east-1 you must pass --create-bucket-configuration LocationConstraint=<region> matching --region, or the call fails. In CI, prefer Terraform for durable buckets; this command suits one-off or test buckets.

Common flags

  • --bucket - the globally unique bucket name (required)
  • --region - target region
  • --create-bucket-configuration LocationConstraint=<region> - required outside us-east-1
  • --acl - canned ACL (often rejected when ACLs are disabled by default)

Example in CI

Create a regional bucket for ephemeral test data.

shell
aws s3api create-bucket --bucket ${TEST_BUCKET} --region eu-west-1 --create-bucket-configuration LocationConstraint=eu-west-1

Common errors in CI

  • An error occurred (BucketAlreadyExists) - the name is taken globally
  • An error occurred (BucketAlreadyOwnedByYou) - you already created it (often safe to ignore)
  • IllegalLocationConstraintException - LocationConstraint does not match --region
  • An error occurred (InvalidLocationConstraint) - LocationConstraint passed for us-east-1

Key takeaways

  • create-bucket needs LocationConstraint matching --region outside us-east-1.
  • BucketAlreadyOwnedByYou is often idempotent-safe in CI scripts.
  • For durable infrastructure, manage buckets with Terraform, not the CLI.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →