Data points are empty on using AWS cli on powershell Data points are empty on using AWS cli on powershell powershell powershell

Data points are empty on using AWS cli on powershell


To answer the question:

Empty datapoints output can return for many reasons, but generally means that there is no data in CloudWatch for your given inputs. Make sure that your inputs are correct and that there is data for the given time period.

I was able to reproduce empty data points in the following scenarios, to give you some idea of how this can produce empty results:

  • Changed a letter on my InstanceId so that it didn't match any of my instances; this doesn't error, just produces empty dataset.
  • Changed time range to before the Instance was in a running state.
  • Used incorrect permissions in powershell, so that the profile I was using didn't have permission to see the Instance I was asking for.

For what it's worth, your syntax is valid. I tested your exact cmdlet against one of my own instances and it worked fine. Once you get your example working, you can get the raw data points by piping the resulting collection and parsing them. For example, assuming the output of your cmdlet is in $datapoints:

$datapoints | % { $_.Datapoints.Average }

To answer the comment:

The syntax -Dimension @{Name = "InstanceId"; Value = "08b290d4ab98f79c3"} is valid for this cmdlet. It looks so strange because the Get-CWMetricStatistics cmdlet expects you to pass in a collection of AWS.CloudWatch.Model.Dimension objects.

In this example, a hash table with matching property names (Name and Value) suffices, but the given example @{'InstanceId'='08b290d4ab98f79c3'} would not because there is no 'InstanceId' parameter on AWS.CloudWatch.Model.Dimension.

In fact, running that returns this error:

Get-CWMetricStatistics : Cannot bind parameter 'Dimension'. Cannot create object of type "Amazon.CloudWatch.Model.Dimension". The InstanceId property was not found for the Amazon.CloudWatch.Model.Dimension object. The available property is: [Name ] , [Value ]

Consider also then that passing a collection of hash tables is valid input for this cmdlet:

-Dimension @(@{Name = "InstanceId"; Value = "i-abcd1234"},@{Name = "InstanceId"; Value = "i-efgh5678"})

Further Reading:

AWS PowerShell Documentation - Get-CWMetricStatistics