Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get total objects and total storage of each folder on S3 bucket

I have an S3 bucket named camera-assets, in that bucket I have a separate folder for each camera and each folder contains millions / billions of files. I want to get a total number of files and storage of each folder in my bucket.

I tried following CLI command:

aws s3api list-objects --bucket camera-assets --prefix 1011-front-external/snapshots/ --output json --query "[sum(Contents[].Size), length(Contents[])]"

But failed to get the result because folder has million/billion of files. It works if there are only a few files.

Please help me to get files count and storage.

like image 752
azharmalik3 Avatar asked Oct 14 '25 04:10

azharmalik3


1 Answers

AWS command line interface tool has --summarize option (have to use along with --recursive), which shows number of objects & total size:

$ aws s3 ls s3://camera-assets --summarize --recursive
   ...
Total Objects: xx
   Total Size: xx
like image 87
Ashish-G Avatar answered Oct 19 '25 11:10

Ashish-G