How to list contents of AWS s3 bucket using python boto3?

You can use AWS SDK for python (boto3) to list all objects and keys (prefix) in an Amazon S3 bucket. The same method can also be used to list all objects (files) in a specific key (folder).

Step 1: Install and configure boto3 in your system

https://cloudaffaire.com/how-to-install-python-boto3-sdk-for-aws/

https://cloudaffaire.com/how-to-configure-python-boto3-sdk-for-aws/

https://pypi.org/project/argparse/

Step 2: Create a python script to list all objects with prefix in S3

Step 3: Exacute the script to list all files and folders in a S3 bucket

Note: The script will return all the objects as pagination logic (max object count 1000) is included in the script. If you have millions or billions of objects in the bucket then modify the script accordingly so that there is no impact on the system you are executing the script.

Leave a Reply