List S3 buckets with s3api
📑 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-identityYou need permission to call s3:ListAllMyBuckets.
The command
aws s3api list-bucketsThe response contains a Buckets array and owner information.
Inspect only what matters
aws s3api list-buckets \
--query "Buckets[].{Name:Name,Created:CreationDate}" \
--output tableThis 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 textOne tiny variation
Sort the buckets by creation date:
aws s3api list-buckets \
--query "sort_by(Buckets, &CreationDate)[].{Name:Name,Created:CreationDate}" \
--output tableCommon 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.