Quick way to list all files in Amazon S3 bucket?

前端 未结 28 1822
星月不相逢
星月不相逢 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 02:01

    First make sure you are on an instance terminal and you have all access of S3 in IAM you are using. For example I used an ec2 instance.

    pip3 install awscli
    

    Then Configure aws

    aws configure
    

    Then fill outcredantials ex:-

    $ aws configure
    AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
    AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
    Default region name [None]: us-west-2
    Default output format [None]: json (or just press enter)
    

    Now, See all buckets

    aws s3 ls
    

    Store all buckets name

    aws s3 ls > output.txt
    

    See all file structure in a bucket

    aws s3 ls bucket-name --recursive
    

    Store file structure in each bucket

    aws s3 ls bucket-name --recursive > file_Structure.txt
    

    Hope this helps.

提交回复
热议问题