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


当前回答

如果你正在寻找特定的文件,比如.jpg图像,你可以执行以下操作:

aws s3 ls s3://your_bucket | grep jpg | wc -l

其他回答

我使用来自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的AWS cloudwatch指标来查看每个桶的确切计数。

如果使用s3cmd命令行工具,可以获得特定桶的递归列表,并将其输出到文本文件。

s3cmd ls -r s3://logs.mybucket/subfolder/ > listing.txt

然后在linux中,您可以对文件运行wc -l来计算行数(每个对象1行)。

wc -l listing.txt

旧线程,但仍然相关,因为我正在寻找答案,直到我明白了这一点。我想使用基于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个文件,并且在不到一分钟的时间内完成了文件计数。

转到AWS计费,然后是报表,然后是AWS使用情况报表。 选择Amazon Simple Storage Service,然后选择Operation StandardStorage。 然后,您可以下载一个CSV文件,该文件包含StorageObjectCount的UsageType,该文件列出每个桶的项目计数。