Learning center

Find why S3 listing fails for one prefix

S3 authorizes ListObjectsV2 with s3:ListBucket on the bucket. A policy can constrain that permission with the requested s3:prefix. Reading an individual object uses a different action and resource.

In an illustrative weekly report job, the bucket policy allows listing for exports/weekly/ but the client passes exports/weekly. An exact StringEquals comparison can deny the second form. Inspect the serialized prefix in the failed request or read the client configuration. If the policy names the intended prefix, check that list request in the same session and keep only the item count.

aws s3api list-objects-v2 --bucket reports-example-444455556666 \
  --prefix exports/weekly/ --max-keys 1 --no-paginate --query KeyCount

Use the result to verify the approved prefix without printing object names. A request specifying a delimiter or other policy-relevant attributes should preserve those attributes in the check. S3 ListObjectsV2 permissions ยท S3 prefix condition key

Trace another denied request.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading