CloudWatch from the Amazon Tools for Windows PowerShell - Amazon Tools for PowerShell
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China.

CloudWatch from the Amazon Tools for Windows PowerShell

This section shows an example of how to use the Tools for Windows PowerShell to publish custom metric data to CloudWatch.

This example assumes that you have set default credentials and a default region for your PowerShell session.

Publish a Custom Metric to Your CloudWatch Dashboard

The following PowerShell code initializes an CloudWatch MetricDatum object and posts it to the service. You can see the result of this operation by navigating to the CloudWatch console.

$dat = New-Object Amazon.CloudWatch.Model.MetricDatum $dat.Timestamp = (Get-Date).ToUniversalTime() $dat.MetricName = "New Posts" $dat.Unit = "Count" $dat.Value = ".50" Write-CWMetricData -Namespace "Usage Metrics" -MetricData $dat

Note the following:

  • The date-time information that you use to initialize $dat.Timestamp must be in Universal Time (UTC).

  • The value that you use to initialize $dat.Value can be either a string value enclosed in quotes, or a numeric value (no quotes). The example shows a string value.

See Also