← All posts
2 min read

S3 bucket naming rules from the CLI

#aws#cli#s3#storage
📑 On this page

Part 11 of AWS from Zero. This is the first deeper S3 lesson.

Before creating buckets, learn the naming rules. S3 bucket names are not just labels. They become part of URLs, policies, logs, and sometimes public endpoints.

What we are learning

An S3 bucket name must be valid before AWS accepts the create command. For general purpose buckets, the most useful beginner rules are:

  • Use 3 to 63 characters.
  • Use lowercase letters, numbers, hyphens, and periods.
  • Start and end with a letter or number.
  • Avoid names that look like IP addresses.
  • Avoid reserved prefixes and suffixes.
  • Assume the name must be unique across all AWS accounts in the AWS partition.

That last rule surprises people. If someone else already owns my-backup-bucket, you cannot create it, even in your own account.

Before you run it

Check who you are and which region you are using:

aws sts get-caller-identity
aws configure get region

Set a region and a name:

REGION="ap-south-1"
BUCKET="aws-zero-s3-names-12345"

Use your own suffix. Bucket names are globally unique, so copy-pasting the exact name may fail.

The command

Ask AWS CLI for the official operation help:

aws s3api create-bucket help

Now create a bucket outside us-east-1:

aws s3api create-bucket \
  --bucket "$BUCKET" \
  --region "$REGION" \
  --create-bucket-configuration LocationConstraint="$REGION"

For regions other than us-east-1, that LocationConstraint matters.

Inspect the result

List buckets and find yours:

aws s3api list-buckets \
  --query "Buckets[?Name=='$BUCKET'].{Name:Name,Created:CreationDate}" \
  --output table

Check the bucket location:

aws s3api get-bucket-location \
  --bucket "$BUCKET" \
  --output table

One tiny variation

Try a bad name mentally before running it:

MyBucket

That has uppercase letters, so it is not a valid general purpose bucket name.

Try another:

192.168.1.1

That looks like an IP address, so it is not allowed either.

Common mistake

If you see:

BucketAlreadyExists

the name is already taken by some AWS account. Pick a more unique name.

If you see:

BucketAlreadyOwnedByYou

you already own that bucket. List it before creating it again.

Cleanup

Delete the empty bucket:

aws s3api delete-bucket \
  --bucket "$BUCKET" \
  --region "$REGION"

Confirm it no longer appears:

aws s3api list-buckets \
  --query "Buckets[?Name=='$BUCKET']"

Next, we will look at the special us-east-1 create-bucket behavior.