AWS SDK Version 3 for .NET
API Reference

AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

Creates or updates an alarm and associates it with the specified metric. Optionally, this operation can associate one or more Amazon SNS resources with the alarm.

When this operation creates an alarm, the alarm state is immediately set to INSUFFICIENT_DATA. The alarm is evaluated and its state is set appropriately. Any actions associated with the state are then executed.

When you update an existing alarm, its state is left unchanged, but the update completely overwrites the previous configuration of the alarm.

If you are an IAM user, you must have Amazon EC2 permissions for some operations:

If you have read/write permissions for Amazon CloudWatch but not for Amazon EC2, you can still create an alarm, but the stop or terminate actions are not performed. However, if you are later granted the required permissions, the alarm actions that you created earlier are performed.

If you are using an IAM role (for example, an EC2 instance profile), you cannot stop or terminate the instance using alarm actions. However, you can still see the alarm state and perform any other actions such as Amazon SNS notifications or Auto Scaling policies.

If you are using temporary security credentials granted using AWS STS, you cannot stop or terminate an EC2 instance using alarm actions.

You must create at least one stop, terminate, or reboot alarm using either the Amazon EC2 or CloudWatch consoles to create the EC2ActionsAccess IAM role. After this IAM role is created, you can create stop, terminate, or reboot alarms using a command-line interface or API.


For .NET Core and PCL this operation is only available in asynchronous form. Please refer to PutMetricAlarmAsync.

Namespace: Amazon.CloudWatch
Assembly: AWSSDK.CloudWatch.dll
Version: 3.x.y.z


public abstract PutMetricAlarmResponse PutMetricAlarm(
         PutMetricAlarmRequest request
Type: Amazon.CloudWatch.Model.PutMetricAlarmRequest

Container for the necessary parameters to execute the PutMetricAlarm service method.

Return Value
The response from the PutMetricAlarm service method, as returned by CloudWatch.


LimitExceededException The quota for alarms for this customer has already been reached.


This example shows how to create an alarm for a metric.

Create metric alarm example

var client = new AmazonCloudWatchClient();

var dimension = new Dimension
  Name = "Desktop Machine Metrics",
  Value = "Virtual Desktop Machine Usage"

var request = new PutMetricAlarmRequest
  ActionsEnabled = true,
  AlarmActions = new List() 
    { "arn:aws:sns:us-east-1:80398EXAMPLE:CodingTestResults" },
  AlarmDescription = "Too many instances offline",
  AlarmName = "Offline Instances",
  ComparisonOperator = ComparisonOperator.GreaterThanOrEqualToThreshold,
  Dimensions = new List() { dimension },
  EvaluationPeriods = 1,
  MetricName = "Desktop Machines Offline",
  Namespace = " Custom Metrics",
  Period = (int)TimeSpan.FromMinutes(5).TotalSeconds,
  Statistic = new Statistic("Maximum"),
  Threshold = 5,
  Unit = StandardUnit.Count


Version Information

.NET Framework:
Supported in: 4.5, 4.0, 3.5

Portable Class Library:
Supported in: Windows Store Apps
Supported in: Windows Phone 8.1
Supported in: Xamarin Android
Supported in: Xamarin iOS (Unified)
Supported in: Xamarin.Forms

See Also