If you want to list the files/objects inside a specific folder within an S3 bucket then you will need to use the list_objects_v2
method with the Prefix
parameter in boto3.
Below are 3 examples codes on how to list the objects in an S3 bucket folder.
- Example 1: List all S3 object keys in a directory using boto3 resource
- Example 2: List all S3 object keys in a directory using boto3 client paginator
- Example 3: List all S3 object keys in a directory S3 Bucket using boto3 client nextContinuationToken
What the code does is that it gets all the files/objects inside the S3 bucket named radishlogic-bucket within the folder named s3_folder/ and adds their keys inside a Python list (s3_object_key_list
). It then prints each of the object keys in the list and also prints the number of files in the folder.