← All posts
2 min read

List S3 buckets with s3api

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

Part 16 of AWS from Zero. Today we list buckets with the low-level S3 API commands.

What we are learning

list-buckets returns the general purpose S3 buckets owned by your AWS account. Unlike object listing, it is an account-level view rather than a view inside one bucket.

Before you run it

aws sts get-caller-identity

You need permission to call s3:ListAllMyBuckets.

The command

aws s3api list-buckets

The response contains a Buckets array and owner information.

Inspect only what matters

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

This gives you a compact inventory with each bucket name and creation date.

To return only bucket names:

aws s3api list-buckets \
  --query "Buckets[].Name" \
  --output text

One tiny variation

Sort the buckets by creation date:

aws s3api list-buckets \
  --query "sort_by(Buckets, &CreationDate)[].{Name:Name,Created:CreationDate}" \
  --output table

Common mistake

Do not expect --region to mean “show buckets in only this Region.” Bucket listing is an account-level operation. When you need the location of one bucket, ask for it:

BUCKET="your-bucket-name"
aws s3api get-bucket-location --bucket "$BUCKET"

An empty location constraint represents us-east-1 for older general purpose bucket behavior.

Cleanup

This lesson creates nothing, so there is nothing to delete.

Next, we will copy an object to another key inside the same bucket.

AWS CLI list-buckets reference