Command
aws s3 lsExplanation
Lists all S3 buckets or, if a specific bucket is provided, lists the contents (objects) within that bucket.
Common Use Cases
- •Verifying bucket creation
- •Viewing bucket contents
- •Checking file uploads
Best Practices
- ✓Use IAM roles with least privilege for listing operations
- ✓Use pagination for large buckets with the `--page-size` flag
Common Mistakes to Avoid
- ⚠Forgetting the trailing slash in the bucket path (`s3://bucket/`)
- ⚠Listing without permissions (missing `s3:ListBucket` policy)
Troubleshooting
Problem: Access denied
Solution: Ensure your IAM user has `s3:ListAllMyBuckets` or `s3:ListBucket` permissions.
Problem: Empty list
Solution: Confirm the bucket name and region are correct.
Examples
List all S3 buckets
aws s3 lsList objects within a specific bucket
aws s3 ls s3://my-bucket/