If you need to list all files/objects inside an AWS S3 Bucket then you will need to use the list_objects_v2 method in boto3.
Below are 3 example codes of how to list all files in a target S3 Bucket.
- Example 1: List all S3 object keys using boto3 resource
- Example 2: List all S3 object keys using boto3 client paginator
- Example 3: List all S3 object keys using boto3 client nextContinuationToken
You can use any of the 3 options since it does the same thing.
It will get all of the files inside the S3 Bucket radishlogic-bucket using Python boto3, put it inside a Python list, then print each object key. It will print the files inside folder recursively, regardless if they are inside a folder or not.
At the end, it will also print the number of items inside the S3 Bucket.Continue reading How to list all objects in an S3 Bucket using boto3 and Python