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?
For Python's boto3 after having used aws configure
:
import boto3
s3 = boto3.resource('s3')
bucket = s3.Bucket('name')
for obj in bucket.objects.all():
print(obj.key)
Update 15-02-2019:
This command will give you a list of all buckets in AWS S3:
aws s3 ls
This command will give you a list of all top-level objects inside an AWS S3 bucket:
aws s3 ls bucket-name
This command will give you a list of ALL objects inside an AWS S3 bucket:
aws s3 ls bucket-name --recursive
This command will place a list of ALL inside an AWS S3 bucket... inside a text file in your current directory:
aws s3 ls bucket-name --recursive | cat >> file-name.txt
s3cmd is invaluable for this kind of thing
$ s3cmd ls -r s3://yourbucket/ | awk '{print $4}' > objects_in_bucket
# find like file listing for s3 files
aws s3api --profile <<profile-name>> \
--endpoint-url=<<end-point-url>> list-objects \
--bucket <<bucket-name>> --query 'Contents[].{Key: Key}'