Skip to content

Instantly share code, notes, and snippets.

@paul-civitas
Created February 22, 2024 01:32
Show Gist options
  • Save paul-civitas/242eea8d2e62730b526d042579e20cb9 to your computer and use it in GitHub Desktop.
Save paul-civitas/242eea8d2e62730b526d042579e20cb9 to your computer and use it in GitHub Desktop.
bucket_list=$(aws s3api list-buckets --no-paginate | jq -r '.Buckets[].Name')
while read -r bucket ; do
echo -n "${bucket},"
aws cloudwatch get-metric-statistics --namespace AWS/S3 --start-time "$yesterday" --end-time "$current_time" --period 86400 --statistics Average --region us-east-1 --metric-name BucketSizeBytes --dimensions Name=BucketName,Value=$bucket Name=StorageType,Value=StandardStorage | jq '(.Datapoints[0].Average // 0)'
done <<< "$bucket_list"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment