Quick way to list all files in Amazon S3 bucket?

前端 未结 28 1823
星月不相逢
星月不相逢 2020-11-28 01:32

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?

28条回答
  •  隐瞒了意图╮
    2020-11-28 01:47

    I'd recommend using boto. Then it's a quick couple of lines of python:

    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 as list.py, open a terminal, and then run:

    $ python list.py > results.txt
    

提交回复
热议问题