title: How can I use AWS Boto3 to get Cloudwatch metric statistics?
body: <p>I'm working on a Python 3 script designed to get S3 space utilization statistics from AWS CloudFront using the Boto3 library.</p>
  
  <p>I started with the AWS CLI and found I could get what I'm after with a command like this:</p>
  
  <pre><code>aws cloudwatch get-metric-statistics --metric-name BucketSizeBytes --namespace AWS/S3 --start-time 2017-03-06T00:00:00Z --end-time 2017-03-07T00:00:00Z --statistics Average --unit Bytes --region us-west-2 --dimensions Name=BucketName,Value=foo-bar Name=StorageType,Value=StandardStorage --period 86400 --output json
  </code></pre>
  
  <p>This returns the data I would expect.  Now I'd like to do the same thing in Python 3 / Boto3.  My code thusfar is:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>from datetime import datetime, timedelta
  import boto3
  
  seconds_in_one_day = 86400  # used for granularity
  
  cloudwatch = boto3.client('cloudwatch')
  
  response = cloudwatch.get_metric_statistics(
      Namespace='AWS/S3',
      Dimensions=[
          {
              'Name': 'BucketName',
              'Value': 'foo-bar'
          },
          {
              'Name': 'StorageType',
              'Value': 'StandardStorage'
          }
      ],
      MetricName='BucketSizeBytes',
      StartTime=datetime.now() - timedelta(days=7),
      EndTime=datetime.now(),
      Period=seconds_in_one_day,
      Statistics=[
          'Average'
      ],
      Unit='Bytes'
  )
  
  print(response)</code></pre>
  </div>
  </div>
  </p>
  
  <p>When I run this, I get a valid response but no datapoints (it's an empty array).  They seem to be identical except the Python method doesn't seem to have a place for the region, where the command line requires it.</p>
  
  <p>One more thing I tried:  my code is computing the dates for the last date versus the command line where they are hard coded.  I did try hard coding the date just to see if I would get data back, and the result was the same.</p>
  
  <p>So my questions are these:</p>
  
  <p>Is the method I'm using in Boto / Python equivalent to the command line?
  Assuming they are, what could I be missing?</p>