Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

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?

closed

1 Answer

0 votes
by (44.4k points)
selected by
 
Best answer

You can use boto which is the AWS SDK for Python. You can do this in a few lines of code:

from boto.s3.connection import S3Connection

conn = S3Connection('access-key','secret-access-key')

bucket = conn.get_bucket('bucket')

for key in bucket.list():

    print key.name.encode('utf-8')

Save this like filename.py, and then run it like this:

$ python filename.py > results.txt

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...