Group S3 keys with a delimiter
📑 On this page
Part 39 of AWS from Zero. This lesson keeps the scope to one S3 behavior you can verify from the terminal.
What we are learning
A delimiter groups keys between the prefix and the next delimiter occurrence. With /, S3 can return folder-like CommonPrefixes.
Before you run it
aws sts get-caller-identity
REGION="ap-south-1"
BUCKET="replace-with-your-private-demo-bucket"Use a private general purpose bucket that you own. Replace every placeholder before running a write or delete command.
The command
aws s3api list-objects-v2 \
--bucket "$BUCKET" \
--prefix "reports/" \
--delimiter "/"A successful configuration command may return no output. Treat inspection as a separate required step.
Inspect the result
aws s3api list-objects-v2 \
--bucket "$BUCKET" \
--prefix "reports/" \
--delimiter "/" \
--query "{Files:Contents[].Key,Groups:CommonPrefixes[].Prefix}"Read the returned fields rather than assuming the write succeeded exactly as intended.
One tiny variation
aws s3api list-objects-v2 \
--bucket "$BUCKET" \
--prefix "reports/2026/" \
--delimiter "/" \
--query "CommonPrefixes[].Prefix" \
--output textMove the prefix one level deeper to explore the next group.
Common mistake
CommonPrefixes are calculated from key names; they are not directory resources you can permission or delete independently.
Cleanup
# This lesson does not require an additional persistent resource.
aws s3api head-bucket --bucket "$BUCKET"Keep the shared demo bucket for the next lesson, or remove only the configuration and objects created here.
Next, we will learn Control S3 listing pagination.