除非我遗漏了什么,否则我所看过的所有api似乎都不会告诉您<S3 bucket>/<文件夹>中有多少对象。有办法统计一下吗?


当前回答

您可以使用s3的AWS cloudwatch指标来查看每个桶的确切计数。

其他回答

我使用来自scalablelogic.com的python脚本(添加计数日志记录)。伟大的工作。

#!/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

现在S3 API有一个简单的解决方案(在AWS cli中可用):

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

或针对特定文件夹:

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

虽然这是一个老问题,并且反馈是在2015年提供的,但现在它要简单得多,因为S3 Web控制台启用了“获取大小”选项:

它提供了以下内容:

旧线程,但仍然相关,因为我正在寻找答案,直到我明白了这一点。我想使用基于gui的工具(即没有代码)进行文件计数。我碰巧已经使用了一个名为3Hub的工具,用于在S3之间进行拖放传输。我想知道我在一个特定的存储区中有多少文件(我不认为计费是按存储区划分的)。

So, using 3Hub, 
- list the contents of the bucket (looks basically like a finder or explorer window)
- go to the bottom of the list, click 'show all'
- select all (ctrl+a)
- choose copy URLs from right-click menu
- paste the list into a text file (I use TextWrangler for Mac) 
- look at the line count  

我在桶中有20521个文件,并且在不到一分钟的时间内完成了文件计数。

截至2020年11月18日,现在有一种更简单的方法来获取这些信息,而无需对API请求征税:

AWS S3存储镜头

默认的,内置的,免费的仪表板允许您查看所有桶的计数,或在“buckets”选项卡下的单个桶。有许多下拉列表可以过滤和排序几乎任何你想要寻找的合理指标。