← All posts
2 min read

List S3 objects under one prefix

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

Part 38 of AWS from Zero. This lesson keeps the scope to one S3 behavior you can verify from the terminal.

What we are learning

S3 keys are flat strings. A prefix such as reports/2026/ narrows listing to keys that begin with that text.

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/2026/"

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/2026/" \
  --query "Contents[].{Key:Key,Size:Size,Updated:LastModified}" \
  --output table

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/07/" \
  --query "Contents[].Key" \
  --output text

A longer prefix narrows the result further without creating a real directory.

Common mistake

Prefixes are case-sensitive and literal. Reports/ and reports/ are different key spaces.

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 Group S3 keys with a delimiter.

Official AWS CLI reference