Get size of an S3 bucket with AWS CLI

Using the AWS CLI, S3 bucket sizes can retrieved.

Finding the S3 Bucket Size

Use the s3 list command with the --summarize option.

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

Output:

1
2
3
4
5
2023-02-27 00:11:33    5.1 KiB object1name
2023-02-06 00:31:42    5.5 KiB object2name

Total Objects: 2
   Total Size: 10.6 KiB

If the output is too noisy, we can retrieve the last 2 lines of the output:

1
aws s3 ls --summarize --human-readable --recursive s3://bucket-name/ | tail -2

Output:

1
2
Total Objects: 2
   Total Size: 10.6 KiB