I have an amazon s3 bucket that has tens of thousands of filenames in it. What\'s the easiest way to get a text file that lists all the filenames in the bucket?
I know its old topic, but I'd like to contribute too.
With the newer version of boto3 and python, you can get the files as follow:
import os
import boto3
from botocore.exceptions import ClientError
client = boto3.client('s3')
bucket = client.list_objects(Bucket=BUCKET_NAME)
for content in bucket["Contents"]:
key = content["key"]
Keep in mind that this solution not comprehends pagination.
For more information: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Client.list_objects