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


当前回答

在s3cmd中,简单地运行以下命令(在Ubuntu系统上):

s3cmd ls -r s3://mybucket | wc -l

其他回答

旧线程,但仍然相关,因为我正在寻找答案,直到我明白了这一点。我想使用基于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 CLI

aws s3 ls s3://mybucket/ --recursive | wc -l 

or

aws cloudwatch get-metric-statistics \
  --namespace AWS/S3 --metric-name NumberOfObjects \
  --dimensions Name=BucketName,Value=BUCKETNAME \
              Name=StorageType,Value=AllStorageTypes \
  --start-time 2016-11-05T00:00 --end-time 2016-11-05T00:10 \
  --period 60 --statistic Average

注意:上面的cloudwatch命令似乎适用于某些人,而不适用于其他人。讨论地点:https://forums.aws.amazon.com/thread.jspa?threadID=217050

使用AWS Web控制台

您可以查看cloudwatch的度量部分,以获得存储的对象的大约数量。

我有大约5000万个产品,使用aws s3 ls花了一个多小时来计数

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

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

计算s3中对象数量的一个最简单的方法是:

步骤1:选择根文件夹

步骤2:点击Actions ->删除(显然,要小心-不要删除它)

第三步:等待几分钟,aws会显示对象的数量和总大小。