How to get the size of an AWS S3 bucket

If you need to get the size of an AWS S3 folder, or even an entire bucket, you can do so with the following command:

aws s3api --profile <your_profile> list-objects --bucket --output json --query "[sum(Contents[].Size), length(Contents[])]" | awk 'NR!=2 {print $0;next} NR==2 {print $0/1024/1024/1024" GB"}'

If you don’t use aws cli profiles, then you can leave out the profile part like this:

aws s3api list-objects --bucket --output json --query "[sum(Contents[].Size), length(Contents[])]" | awk 'NR!=2 {print $0;next} NR==2 {print $0/1024/1024/1024" GB"}'

Remember to replace <bucket_name> with your own bucket name.

Tags:
0 0 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments