How can I tell how many objects I've stored in an S3 bucket?

后端 未结 29 3522
逝去的感伤
逝去的感伤 2020-12-02 04:45

Unless I\'m missing something, it seems that none of the APIs I\'ve looked at will tell you how many objects are in an /. Is ther

相关标签:
29条回答
  • 2020-12-02 05:30

    There is an easy solution with the S3 API now (available in the AWS cli):

    aws s3api list-objects --bucket BUCKETNAME --output json --query "[length(Contents[])]"
    

    or for a specific folder:

    aws s3api list-objects --bucket BUCKETNAME --prefix "folder/subfolder/" --output json --query "[length(Contents[])]"
    
    0 讨论(0)
  • 2020-12-02 05:31

    In s3cmd, simply run the following command (on a Ubuntu system):

    s3cmd ls -r s3://mybucket | wc -l
    
    0 讨论(0)
  • 2020-12-02 05:34

    You can easily get the total count and the history if you go to the s3 console "Management" tab and then click on "Metrics"... Screen shot of the tab

    0 讨论(0)
  • 2020-12-02 05:34

    You can just execute this cli command to get the total file count in the bucket or a specific folder

    Scan whole bucket

    aws s3api list-objects-v2 --bucket testbucket | grep "Key" | wc -l
    aws s3api list-objects-v2 --bucket BUCKET_NAME | grep "Key" | wc -l
    

    you can use this command to get in details

    aws s3api list-objects-v2 --bucket BUCKET_NAME
    

    Scan a specific folder

    aws s3api list-objects-v2 --bucket testbucket --prefix testfolder --start-after testfolder/ | grep "Key" | wc -l
    
    aws s3api list-objects-v2 --bucket BUCKET_NAME --prefix FOLDER_NAME --start-after FOLDER_NAME/ | grep "Key" | wc -l
    
    0 讨论(0)
  • 2020-12-02 05:35

    Go to AWS Billing, then reports, then AWS Usage reports. Select Amazon Simple Storage Service, then Operation StandardStorage. Then you can download a CSV file that includes a UsageType of StorageObjectCount that lists the item count for each bucket.

    0 讨论(0)
提交回复
热议问题