sashoalm
sashoalm

Reputation: 79507

Modify existing AWS alarm with AWS-CLI

How can I modify an existing AWS alarm without figuring out all the parameters? Say if I just want to change a single property.

I tried getting its properties with aws cloudwatch describe-alarms --alarm-names my-alarm, then modifying the json, and passing it with:

aws cloudwatch put-metric-alarm --alarm-name my-alarm --cli-input-json '<minified json>'

But I'm getting errors:

Parameter validation failed:
Missing required parameter in input: "MetricName"
Missing required parameter in input: "Namespace"
Missing required parameter in input: "Period"
...

I saw Modify Existing alarms AWS, but it uses the AWS SDK with C#, I'm looking for a CLI solution.

Upvotes: 4

Views: 3841

Answers (3)

Calamity 418
Calamity 418

Reputation: 1

As a partial workaround, you can see the entire source of a Cloudwatch alarm in the console:

  1. Cloudwatch - Alarms - Open up your alarm
  2. In the upper right hand corner choose Actions - View Source.

You'll have the option to see all its parameters in Cloudformation Json/YAML or AWS Cli format...takes just a few moments to create a script you can modify and apply from there.

Upvotes: 0

Aress Support
Aress Support

Reputation: 1425

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

This is clearly mentioned at: https://docs.aws.amazon.com/cli/latest/reference/cloudwatch/put-metric-alarm.html

You need to explicitly mention all the parameters as it will override the previous parameters.

Upvotes: -1

John Rotenstein
John Rotenstein

Reputation: 269490

From put-metric-alarm — AWS CLI Command Reference:

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

Therefore, it seems that you will need to specify all the parameters, rather than just the parameter you wish to modify.

Upvotes: 4

Related Questions