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

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

    Here's the boto3 version of the python script embedded above.

    import sys
    import boto3
    
    s3 = boto3.resource('s3')
    s3bucket = s3.Bucket(sys.argv[1])
    size = 0
    totalCount = 0
    
    for key in s3bucket.objects.all():
        totalCount += 1
        size += key.size
    
    print('total size:')
    print("%.3f GB" % (size*1.0/1024/1024/1024))
    print('total count:')
    print(totalCount)`
    

提交回复
热议问题