Created
October 31, 2023 14:18
-
-
Save kennycyb/f533270ffa50bea6392704a4748a2627 to your computer and use it in GitHub Desktop.
AWS | S3 | Calculate Objects Size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` | |
#!/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