Can AWS CloudWatch alarms be paused/disabled during specific hours?
amazon-cloudwatch, amazon-web-services
Solution
Another idea is using math expressions. In the simplest case a combination of `IF` and `HOUR` could help. This can be done directly in cloudwatch without lambda functions.
An example to illustrate the idea: Assume a metric `m` that takes only natural numbers as values and an alarm triggered if `m=0`. Then you could use the expression
IF(HOUR(m) > 8 && HOUR(m) < 18, m, m+0.01)
instead of `m` in the alarm. Note that `HOUR` returns the hour in UTC, so adjust it to your time zone. The `0.01` is only added if hour is outside of the interval [8, 18]. In case `m` is actually `0` the extra `0.01` ensures that the alarm checking for `0` is not triggered. `0.01` is an arbitrary value that must be small enough to not changing the meaning of your metric. Finding such a number might not be possible for all metrics. I think you get the idea.
To add a math expression to an alarm definition via Cloudwatch UI, click buttons in the following order:
- During alarm creation: Select metric -> View graphed metrics -> Add math expression
- Or during editing an alarm: Edit (in the first step Specify metric and conditions) -> Add math expression
(This question is one of the top google search results so I wanted to add a workaround which helped me.)
Problem
I want to automatically toggle alarms on/off during specific periods of time so that they do not fire during maintenance windows. I'm doubting that an easy or direct method exists since I could not find such a thing in the documentation. Does anyone know of a different approach to achieve this while still using CloudWatch alarms, or did I miss an obvious solution?