Skip to content

Instantly share code, notes, and snippets.

@ns-mkusper
Last active April 15, 2019 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ns-mkusper/912aeba43e8d5b3aee8a83af1aaaa9fe to your computer and use it in GitHub Desktop.
Save ns-mkusper/912aeba43e8d5b3aee8a83af1aaaa9fe to your computer and use it in GitHub Desktop.
import boto3
from datetime import datetime, timedelta
regions = [
"ap-northeast-1", "ap-northeast-2", "ap-south-1", "ap-southeast-1",
"eu-central-1", "eu-west-1", "eu-west-2", "us-east-1", "us-east-2",
"us-west-1", "us-west-2"
]
for region in regions:
bucket_name = "EXAMPLEBUCKET"
cloudwatch = boto3.client('cloudwatch', region_name=region)
response = cloudwatch.get_metric_statistics(
Namespace="AWS/S3",
MetricName="BucketSizeBytes",
Dimensions=[{
"Name": "BucketName",
"Value": bucket_name
}, {
"Name": "StorageType",
"Value": "StandardStorage"
}],
StartTime=datetime.now() - timedelta(days=1),
EndTime=datetime.now(),
Period=86400,
Statistics=['Average'])
bucket_size_bytes = response['Datapoints'][-1]['Average']
print(bucket_name + " " + str(bucket_size_bytes))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment