DEV Community

Jonathan M.
Jonathan M.

Posted on

How to list buckets by name and size to measure Billing and other analyzes.

#!/bin/bash
aws_profile=('profile1' 'profile2');

#loop AWS profiles
for i in "${aws_profile[@]}"; do
  echo "${i}"
  buckets=($(aws --profile "${i}" --region <region> s3 ls s3:// --recursive | awk '{print $3}'))

  #loop S3 buckets
  for j in "${buckets[@]}"; do
  echo "${j}"
  aws --profile "${i}" --region <region> s3 ls s3://"${j}" --recursive --human-readable --summarize | awk END'{print}'
  done

done

Top comments (0)