DEV Community

Cover image for Script to list the S3 Bucket storage size
Kannan
Kannan

Posted on

Script to list the S3 Bucket storage size

If we need to fetch the S3 bucket storage size we need to trace via individual bucket under metrics we get the storage size.
on one go use the below script to get the bucket name with storage size.

s3list=`aws s3 ls | awk  '{print $3}'`
for s3dir in $s3list
do
    echo $s3dir
    aws s3 ls "s3://$s3dir"  --recursive --human-readable --summarize | grep "Total Size" 
done
Enter fullscreen mode Exit fullscreen mode
  1. create the .sh file
  2. copy the code on the file
  3. Excecute the script to get the s3 bucket details

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more