Scenario: There are so many buckets which we are consuming for data stroage. Some of these buckets are costing huge amount to us. Now, we need to find out which bucket is costing more amount so we can plan for data archive.
We need to create the excel sheet which will contain the name of the bucket and the storage occupied by the files in those bucket. The s3 service charges is $0.25 per GB so accordingly we can apply formula in our excel sheet.
- Configure
AWS CLI
on your machine withACCESS KEY and SECRET ACCESS KEY.
- Make sure that user have required permission if not then attach an
IAM policy.
- Create a shell script on your your
linux
machine.
cat > s3Usage.sh
Paste the below content and hit Enter
for bucket in $(aws s3 ls --profile default | awk '{print $3}')
do
bucketsize=$(aws s3 ls --summarize --recursive s3://$bucket --profile default | grep 'Total Size' | awk '{print $3}')
echo $bucket,$bucketsize >> s3usage.csv
done
echo "Your file has been saved at $PWD/s3usage.csv"