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

后端 未结 29 3676
逝去的感伤
逝去的感伤 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:19

    I used the python script from scalablelogic.com (adding in the count logging). Worked great.

    #!/usr/local/bin/python
    
    import sys
    
    from boto.s3.connection import S3Connection
    
    s3bucket = S3Connection().get_bucket(sys.argv[1])
    size = 0
    totalCount = 0
    
    for key in s3bucket.list():
        totalCount += 1
        size += key.size
    
    print 'total size:'
    print "%.3f GB" % (size*1.0/1024/1024/1024)
    print 'total count:'
    print totalCount
    

提交回复
热议问题