Amazon S3 capability
List Amazon S3 objects by prefix
Use ListObjectsV2 or aws s3api list-objects-v2 to enumerate keys under a prefix in a general purpose S3 bucket. Both methods operate on key prefixes.
Documentation reviewed
Ways to do it
API
GET /?list-type=2
Send a signed request to the bucket endpoint. Use the prefix parameter and continue with the returned NextContinuationToken when the response is truncated.
- Requirements
- The general purpose bucket name and permission for s3:ListBucket.
- Limitations
- One response returns at most 1,000 keys. The response can include fewer matches and a continuation token.
CLI
aws s3api list-objects-v2
Run the AWS CLI command with the bucket name and desired prefix. The CLI can retrieve multiple result pages.
- Requirements
- An AWS CLI configuration with credentials authorized for s3:ListBucket.
- Limitations
- The CLI paginates by default. Use --max-items to cap output and resume with the CLI’s --starting-token when one is returned.
Example
aws s3api list-objects-v2 --bucket "$BUCKET" --prefix 'reports/' --max-items 25