Menu
AWS Tools for Windows PowerShell
User Guide

CloudWatch from the AWS 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. Therefore, credentials and a region are not included in the invocation of the cmdlets.

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). A string value is shown previously.

See Also