How to get the size of an AWS S3 bucket

0 min read 88 words

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  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:
Andrew
Andrew

Andrew is a visionary software engineer and DevOps expert with a proven track record of delivering cutting-edge solutions that drive innovation at Ataiva.com. As a leader on numerous high-profile projects, Andrew brings his exceptional technical expertise and collaborative leadership skills to the table, fostering a culture of agility and excellence within the team. With a passion for architecting scalable systems, automating workflows, and empowering teams, Andrew is a sought-after authority in the field of software development and DevOps.

Tags