Skip to content

Instantly share code, notes, and snippets.

@kennycyb
Created October 31, 2023 14:18
Show Gist options
  • Save kennycyb/f533270ffa50bea6392704a4748a2627 to your computer and use it in GitHub Desktop.
Save kennycyb/f533270ffa50bea6392704a4748a2627 to your computer and use it in GitHub Desktop.
AWS | S3 | Calculate Objects Size
```
#!/bin/bash
# Define the name of the CSV file
file="bucket_list.csv"
# Read the CSV file and calculate the size of each bucket
while IFS=',' read -r name region
do
echo "Calculating size of bucket: $name in region $region"
size=$(aws s3 --region $region ls s3://$name --recursive | awk 'BEGIN {total=0}{total+=$3}END{print total/1024/1024" MB"}')
echo "$name,$region,$size MB"
echo "$name,$region,$size MB" >> bucket_size.csv
done < "$file"
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment