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


当前回答

现在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[])]"

其他回答

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

现在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[])]"

3Hub已停产。有一个更好的解决方案,你可以使用传输(仅Mac),然后你只需连接到你的桶,并从视图菜单中选择显示项目计数。

选择桶/文件夹->单击动作->单击计算总大小

您可能会使用Amazon S3库存,它将在csv文件中为您提供对象列表