LoginSignup
14
4

More than 3 years have passed since last update.

CloudWatchアラームのアクションを無効にする。

Posted at

はじめに

CloudWatchアラームを設定したけれど、一時的に通知をOFFにしたいなどがあると思います。例えばメンテナンス作業などで不要なアラーム飛ばしたくない場合など。
ということで、アラームの状態確認方法・アクションの無効化/有効化についてまとめました。

確認方法

ここでは 管理コンソールaws-cli による確認方法を行います。

コンソール

CloudWatchコンソール > アラーム」 から 歯車アイコン をクリックします。
スクリーンショット 2020-12-23 12.39.53.png

アクションが有効になっています を有効にします。
スクリーンショット 2020-12-13 17.56.13のコピー.png

すると以下の画像のように 有効 という文字が表示されます。
スクリーンショット 2020-12-13 17.58.41.png
ちなみに、アラームアクションはデフォルト有効です。

aws-cli

特定アラームの状態については以下のコマンドで確認ができます。

describe-alarms
$ aws cloudwatch describe-alarms --alarm-names <アラーム名>
出力例
{
    "MetricAlarms": [
        {
            "EvaluationPeriods": 2,
            "AlarmArn": "arn:aws:cloudwatch:us-east-1:123456789012:alarm:myalarm",
            "StateUpdatedTimestamp": "2014-04-09T18:59:06.442Z",
            "AlarmConfigurationUpdatedTimestamp": "2012-12-27T00:49:54.032Z",
            "ComparisonOperator": "GreaterThanThreshold",
            "AlarmActions": [
                "arn:aws:sns:us-east-1:123456789012:myHighCpuAlarm"
            ],
            "Namespace": "AWS/EC2",
            "AlarmDescription": "CPU usage exceeds 70 percent",
            "StateReasonData": "{\"version\":\"1.0\",\"queryDate\":\"2014-04-09T18:59:06.419+0000\",\"startDate\":\"2014-04-09T18:44:00.000+0000\",\"statistic\":\"Average\",\"period\":300,\"recentDatapoints\":[38.958,40.292],\"threshold\":70.0}",
            "Period": 300,
            "StateValue": "OK",
            "Threshold": 70.0,
            "AlarmName": "myalarm",
            "Dimensions": [
                {
                    "Name": "InstanceId",
                    "Value": "i-0c986c72"
                }
            ],
            "Statistic": "Average",
            "StateReason": "Threshold Crossed: 2 datapoints were not greater than the threshold (70.0). The most recent datapoints: [38.958, 40.292].",
            "InsufficientDataActions": [],
            "OKActions": [],
            "ActionsEnabled": true,
            "MetricName": "CPUUtilization"
        }
    ]
}

--alarm-namesなので複数のアラームを確認したいのであればスペースで続けて指定すれば確認できます。
また、全てのアラームについて確認したい場合はオプション無しでOKです。

アクションステータス変更

まず、変更方法を調べたところドキュメントには以下の様に記載されていました。

ー 引用
アラームを無効または有効にするには、CloudWatch コンソール、DisableAlarmActions および EnableAlarmActions API アクション、または AWS CLI の disable-alarm-actions および enable-alarm-actions コマンドを使用します。

CloudWatchコンソール とあるので管理コンソールからでも操作ができるのかと思ったのですが、、、見つかりません。仕方なくサポートに問い合わせて確認してみました。
すると、 「現時点において CloudWatch コンソールではアラームの無効化および有効化が行えません。」 との回答が。。。
ということで、アクションの無効化および有効化は aws-cli または sdk からのみ行えるそうです。(2020/12/14時点)

アクション無効化

ここでは IAMPolicyChanges というアラーム名に対して無効化してみます。

無効化
$ aws cloudwatch disable-alarm-actions --alarm-names IAMPolicyChanges
アクションステータスの確認
$ aws cloudwatch describe-alarms --alarm-names IAMPolicyChanges | grep ActionsEnabled
            "ActionsEnabled": false, 

ActionsEnabledfalse となれば無効になっている証拠です。
コンソールの場合は 無効 と表示されます。
スクリーンショット 2020-12-13 22.47.05.png

アクション有効化

今度は先ほど無効にしたアラームを有効に戻します。

有効化
$ aws cloudwatch enable-alarm-actions --alarm-names IAMPolicyChanges
アクションステータスの確認
$ aws cloudwatch describe-alarms --alarm-names IAMPolicyChanges | grep ActionsEnabled
            "ActionsEnabled": true,

おわりに

アクションを無効化/有効化するのにaws-cliやsdkを使わないといけないのは運用的に少々(かなり)面倒ですよね。。。
サポートへも要望挙げておいたので、早くコンソールから操作できるようになって欲しいなと思います。

参考

Amazon CloudWatch でのアラームの使用 - CloudWatch アラームでよく使用する機能
Amazon CloudWatch でのアラームの使用
AWS CLI Command Reference - cloudwatch

14
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
4