def s3_cw_metrics()

in source/lib/cloudwatch.py [0:0]


    def s3_cw_metrics(self, bucket_name):
        try:
            cw_client = boto3.client('cloudwatch')
            response = cw_client.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=300,
                Statistics=['Average']
            )
            if not response['Datapoints']:
                self.logger.debug("S3 bucket size is zero. This is an empty bucket.")
                return '0'
            else:
                bucket_size_bytes = response['Datapoints'][-1]['Average']
                return Decimal(bucket_size_bytes)
        except Exception as e:
            self.logger.error("unhandled exception: CloudWatchMetric_s3_cw_metrics", exc_info=1)