AWS S3 : List files using Python code

Below is a simple python code to list files under a specific directory in s3 bucket. You should have boto3 installed.

import boto3
#Modify the bucket name 
s3Bucket = 'MY_BUCKET'
#Prefix should contain the base directory whose files you want to list
prefix = 'tmp/'
if 'Contents' in objects:
    contents = objects['Contents']
    for file in contents:

Leave a Reply

Your email address will not be published. Required fields are marked *