s3 pull file list

PHOTO EMBED

Thu Jan 26 2023 15:39:27 GMT+0000 (Coordinated Universal Time)

Saved by @praveenms079 #s3 #aws

import boto3

# Create an S3 client
s3 = boto3.client('s3')

# Set the name of the S3 bucket and the folder prefix
bucket_name = 'my-bucket'
folder_prefix = 'path/to/folder/'

# Use the S3 client to list the objects in the bucket
result = s3.list_objects_v2(Bucket=bucket_name, Prefix=folder_prefix)

# Extract the list of files from the response
files = [content['Key'] for content in result.get('Contents', [])]

# Print the list of files
print(files)
content_copyCOPY