zabop
zabop

Reputation: 7832

How do I find the exact number of bytes of my AWS S3 bucket using AWS CLI?

This thread: How do I find the total size of my AWS S3 storage bucket or folder? describes how to get the total filesize in an S3 bucket, but the result is not byte level accurate. I would need to know the exact number of bytes in the bucket.

This answer confirms my own observation, that the command

aws s3 ls --summarize --human-readable --recursive s3://bucket-name/

is not giving an output which is has byte level accuracy (tested it, and example output also confirms this). Similar advice is given here, here and here.

This thread: Check file size on S3 without downloading? describes a way which could be used, but provides no code.

The bucket is around half a terabyte with a few tens of thousands of files. It is just a one-off thing, I do not have to do this frequently.

Upvotes: 1

Views: 1943

Answers (2)

TimurM
TimurM

Reputation: 11

Use the same command but without the "human-readable" flag, then it will show size in bytes:

aws s3 ls --summarize --recursive s3://bucket-name/

From the documentation:

--human-readable (boolean) Displays file sizes in human readable format.

Upvotes: 1

Marcin
Marcin

Reputation: 238051

The easiest way is to use BucketSizeBytes metric in CloudWatch. For more granual size information you can request S3 inventory.

Upvotes: 1

Related Questions