I Tried Using Tag Propagation to Stop Recovery Notifications on a Per-Alarm Basis in CloudWatch Alarms

I Tried Using Tag Propagation to Stop Recovery Notifications on a Per-Alarm Basis in CloudWatch Alarms

Enabling tag propagation for CloudWatch Alarms puts the alarm's tags into EventBridge events. I tagged only the alarms whose recovery (OK) notifications I wanted to stop and blocked them with a rule, and also showed severity from tags in the message.
2026.11.29

This page has been translated by machine translation. View original

Hello! This is Yoshida from the Cloud Business Division.

When you send CloudWatch Alarm notifications through EventBridge rules, you receive both the notification for when the alarm goes to ALARM and the one for when it returns to OK (recovery). Once you have a mix of alarms that need recovery notifications and alarms that don't, separating them per alarm in rules is a hassle.

So I tried using CloudWatch Alarm tag propagation. When tag propagation is enabled, the alarm's tags (alarmTags) are included in the EventBridge event. I attached a NotifyRecovery=false tag only to the alarms whose recovery notifications I wanted to stop, and set up the rule's event pattern to block them. In addition, I made the severity shown in the notification text come from a tag as well.

The tag propagation feature itself is introduced in the following article. This article summarizes how I used it to control notifications.

[Update] Amazon CloudWatch alarms can now include tags in the notification payload | DevelopersIO

The setup I tried is the "aggregated CloudWatch Alarm notification" from the following article. Events from a Metrics Insights query alarm are processed by Step Functions and then received by a rule on a custom bus. All I change this time is the event pattern and target of that rule. Even if you don't aggregate, I think you can use the same approach as long as you receive alarm events with an EventBridge rule.

If you want to show the source account ID in aggregated CloudWatch Alarm notifications, extract it with Step Functions | DevelopersIO

Background

While testing notifications with a test alarm, both ALARM and OK notifications arrived, and the question came up: "Can we stop the recovery notifications?"

For now, receiving recovery notifications isn't a problem. However, as operations continue, I expect that some alarms will need recovery notifications and others won't.

An example of an alarm that doesn't need recovery notifications is one that counts errors. If it's configured to go to ALARM on even a single error, it returns to OK immediately once the count is 0 in the next period. The recovery notification arrives even though the cause hasn't been fixed, so it doesn't mean "resolved" even when it arrives.

If you only want to separate by state, adding a detail.state.value condition to the rule's event pattern is enough. However, if you send only recovery notifications to a separate destination, the number of rules per severity doubles. And if you want to decide per alarm whether recovery notifications are needed, you would end up listing alarm names in the rule's conditions. Having to fix the rule every time you add an alarm is a hassle.

So I decided to have the alarm itself carry whether recovery notifications are needed. What I used for that is alarm tag propagation.

Tag propagation puts tags in the event

Tag propagation is enabled per alarm. In the AWS CLI, set AlarmTagsPropagation to true in ActionConfiguration of put-metric-alarm. In the console, when creating or editing an alarm, under "Add alarm details", check "Include this alarm's tags in the action payload and event payload" below the tag editor.

The definition of the test alarm this time is as follows. It monitors a custom metric in a member account with a Metrics Insights query.

{
  "AlarmName": "low-test-custom-AlarmTagPropagation",
  "Metrics": [
    {
      "Id": "q1",
      "Expression": "SELECT MAX(TestErrorCountTagPropagation) FROM \"Custom/AlarmTest\" GROUP BY AWS.AccountId, TestResourceId ORDER BY MAX() DESC",
      "Period": 60,
      "ReturnData": true
    }
  ],
  "EvaluationPeriods": 1,
  "DatapointsToAlarm": 1,
  "Threshold": 1,
  "ComparisonOperator": "GreaterThanOrEqualToThreshold",
  "TreatMissingData": "notBreaching",
  "Tags": [{ "Key": "NotifyRecovery", "Value": "true" }],
  "ActionConfiguration": { "AlarmTagsPropagation": { "Enabled": true } }
}
aws cloudwatch put-metric-alarm --cli-input-json file://alarm-low-test-tag-propagation.json

To enable tag propagation, the person creating or updating the alarm needs the cloudwatch:ListTagsForResource permission.

A principal that creates or updates an alarm to enable this configuration must have the cloudwatch:ListTagsForResource permission for that alarm.

(Translation: A principal that creates or updates an alarm to enable this configuration must have the cloudwatch:ListTagsForResource permission for that alarm.)

Alarm tags in action payloads - Amazon CloudWatch

I triggered the alarm and looked at the event sent to the custom bus after passing through Step Functions. The main parts of detail are as follows.

{
  "alarmName": "low-test-custom-AlarmTagPropagation",
  "state": { "value": "ALARM" },
  "alarmTags": { "NotifyRecovery": "true" },
  "alarmTagsStatus": "SUCCESS",
  "sourceAccountId": "222222222222",
  "resourceSummary": "TestResourceId=test-resource-001"
}

alarmTags and alarmTagsStatus were also included in the event emitted by a Metrics Insights query alarm (CloudWatch Alarm Contributor State Change). Step Functions leaves the original event's detail as it is and sends it after adding sourceAccountId and so on, so the tags remain.

On the other hand, events from alarms without tag propagation configured include neither alarmTags nor alarmTagsStatus. This matters for how the event pattern is written, as described later.

When you change an alarm's tags, the change is reflected from the event for the next state change. You can change the behavior just by changing tags, without touching the rule.

Attach the tag only to alarms whose recovery notifications you want to stop

When using tags to decide whether recovery notifications are needed, there are two approaches depending on how you treat alarms without the tag.

Approach Alarms to tag Alarms without the tag
Opt-in NotifyRecovery=true on alarms that need recovery notifications No recovery notification arrives
Opt-out NotifyRecovery=false on alarms whose recovery notifications you want to stop Recovery notification arrives

With either approach, ALARM notifications arrive regardless of the tag.

This time I went with opt-out, for three reasons.

  • More alarms benefit from recovery notifications
    • Alarms for CPU utilization or remaining disk space stay in ALARM while the value exceeds the threshold. When a recovery notification arrives, you know the value has returned to normal
    • The ones you want to stop are a few alarms, such as those that count occurrences. Tagging the smaller group takes less effort
  • Forgetting to tag fails on the safe side
    • If you forget to tag with opt-out, you just receive extra recovery notifications
    • If you forget to tag with opt-in, recovery notifications don't arrive, and you can't tell from notifications whether an incident has subsided
  • Introducing it doesn't change the behavior of existing alarms
    • At the moment the rule is changed, every alarm still gets both ALARM and OK as before
    • You don't need to go around tagging existing alarms; you can just tag them one by one as ones you want to stop come up

The original rule's event pattern only sorts by the alarm name prefix (low-). I added $or to this detail. The opt-out event pattern is as follows.

{
  "source": ["custom.cloudwatch.alarm"],
  "detail-type": ["CloudWatch Alarm Contributor State Change"],
  "detail": {
    "alarmName": [{ "prefix": "low-" }],
    "$or": [
      { "state": { "value": ["ALARM"] } },
      { "state": { "value": ["OK"] }, "alarmTags": { "NotifyRecovery": [{ "exists": false }] } },
      { "state": { "value": ["OK"] }, "alarmTags": { "NotifyRecovery": [{ "anything-but": "false" }] } }
    ]
  }
}

The contents of $or are, from the top, three conditions: "ALARM", "OK with no NotifyRecovery", and "OK with NotifyRecovery other than false".

For opt-in, make $or two conditions: "ALARM" and "OK with NotifyRecovery set to true".

"$or": [
  { "state": { "value": ["ALARM"] } },
  { "state": { "value": ["OK"] }, "alarmTags": { "NotifyRecovery": ["true"] } }
]

With anything-but alone, recovery notifications for untagged alarms are also stopped

Looking at the opt-out pattern, "other than false" seems like it could be written with anything-but alone. However, with anything-but alone, even the recovery notifications of alarms without the tag would be stopped.

An EventBridge event pattern doesn't match if a field written in the pattern is absent from the event.

For an event pattern to match an event, the event must contain all the field names listed in the event pattern.

Event pattern syntax - Amazon EventBridge

anything-but: "false" means "the value is anything other than false", but before comparing values, it assumes that detail.alarmTags.NotifyRecovery exists in the event. The OK event of an alarm without the tag doesn't have this field. If tag propagation isn't configured, alarmTags itself doesn't exist.

The table below summarizes, for each alarm, which way of writing the pattern lets the recovery notification arrive.

Alarm NotifyRecovery in the event anything-but only Also with exists: false
Tagged with NotifyRecovery=false "false" Doesn't arrive Doesn't arrive
Tagged with another value such as NotifyRecovery=true "true" Arrives Arrives
Not tagged Absent Doesn't arrive Arrives

If you write it with anything-but alone, even though the intent is "tag only the alarms you want to stop", the recovery notifications of the majority of alarms without the tag are stopped too. That is the opposite of the intent of opt-out. That is why I placed the condition "OK with no NotifyRecovery (exists: false)" as a separate element of $or.

Results

Judging with test-event-pattern

Before changing the rule, I checked with aws events test-event-pattern. It lets you verify whether an event pattern matches an event without creating any resources.

I extracted the events from the Step Functions execution history when I triggered the test alarms.

aws events test-event-pattern \
  --event-pattern file://patterns-built/low-optout.json \
  --event file://events/untagged-ok.json \
  --query Result --output text

The results are as follows.

Event Opt-in Opt-out
ALARM, NotifyRecovery=true True True
OK, NotifyRecovery=true True True
OK, no tag False True
ALARM, NotifyRecovery=false - True
OK, NotifyRecovery=false - False

Checking with actual notifications

Next, I rewrote the rule's event pattern and checked using the notification emails that arrived. I triggered a tagged test alarm and a test alarm without tag propagation at the same time. For both, sending a metric once puts them in ALARM, and after about 6 minutes the data stops and they return to OK.

The results with the opt-in pattern, with the tagged alarm set to NotifyRecovery=true, are as follows.

Alarm ALARM notification OK notification
Tagged (true) Arrived Arrived
No tag Arrived Did not arrive

The results with the opt-out pattern, with the tagged alarm changed to NotifyRecovery=false, are as follows.

Alarm ALARM notification OK notification
Tagged (false) Arrived Did not arrive
No tag Arrived Arrived

Both are as expected. Even for the OK notifications that didn't arrive, the events did reach the custom bus and were stopped by the rule's event pattern. Whether an alarm has returned to OK is hard to judge just from no email arriving, so I confirmed it by the contributor disappearing from the list of describe-alarm-contributors.

aws cloudwatch describe-alarm-contributors --alarm-name low-test-custom-AlarmTagPropagation

Show severity in the text from tags too

As another use of tag propagation, I made the severity shown in the notification text come from a tag as well.

In previous articles, I wrote the severity directly, like [LOW], in the target's Input Transformer. Because you duplicate and rewrite the target in each per-severity rule, it's a setup prone to missed edits.

I attach an AlarmLevel tag (CRITICAL, HIGH, MEDIUM, LOW) to the alarm, enable tag propagation, and add "alarmLevel": "$.detail.alarmTags.AlarmLevel" to InputPathsMap. In the text you can write <alarmLevel>, so the text is the same across the targets of the four rules.

"InputPathsMap": {
  "alarmDescription": "$.detail.configuration.description",
  "alarmName": "$.detail.alarmName",
  "region": "$.region",
  "resourceSummary": "$.detail.resourceSummary",
  "sourceAccountId": "$.detail.sourceAccountId",
  "stateReason": "$.detail.state.reason",
  "stateTimestamp": "$.detail.state.timestamp",
  "stateValue": "$.detail.state.value",
  "alarmLevel": "$.detail.alarmTags.AlarmLevel"
},
"InputTemplate": "{\"subject\":\"[<alarmLevel>] <alarmName> - <sourceAccountId>\",\"message\":\"アラーム名: <alarmName> \\n説明: <alarmDescription>\\n重要度: <alarmLevel> \\nアカウントID: <sourceAccountId> \\nリソース情報: <resourceSummary> \\nリージョン: <region> \\n状態: <stateValue> \\n遷移時刻: <stateTimestamp> \\n理由: \\n<stateReason>\",\"topicArn\":\"arn:aws:sns:ap-northeast-1:111111111111:alarm-verification-topic\"}"

When I triggered a test alarm with AlarmLevel=LOW, both ALARM and OK arrived with text containing LOW in the subject and body. The OK notification is as follows.

件名: [LOW] low-test-custom-AlarmTest - 222222222222

アラーム名: low-test-custom-AlarmTest
説明: 通知パイプラインの動作確認用テストアラーム(low)。メンバーアカウントのカスタムメトリクスCustom/AlarmTestのTestErrorCountLowで発火させる
重要度: LOW
アカウントID: 222222222222
リソース情報: TestResourceId=test-resource-001
リージョン: ap-northeast-1
状態: OK
遷移時刻: 2026-10-28T09:02:38.740+0000
理由:
No data was returned for this contributor

AlarmLevel and NotifyRecovery can be attached to a single alarm together. For a HIGH alarm whose recovery notifications you want to stop, attach them at creation time like this.

aws cloudwatch put-metric-alarm \
  ...(アラームの設定) \
  --tags Key=AlarmLevel,Value=HIGH Key=NotifyRecovery,Value=false \
  --action-configuration '{"AlarmTagsPropagation": {"Enabled": true}}'

When tagging an existing alarm

When adding tags to an existing alarm later, you can't do it with --tags of put-metric-alarm. Tags is applied only when the alarm is newly created.

If you are using this operation to update an existing alarm, any tags you specify in this parameter are ignored. To change the tags of an existing alarm, use TagResource or UntagResource.

(Translation: If you use this operation to update an existing alarm, any tags specified in this parameter are ignored. To change the tags of an existing alarm, use TagResource or UntagResource.)

PutMetricAlarm - Amazon CloudWatch

No error occurs and it ends without the tags being attached, so it's easy to miss. For an existing alarm, attach tags with tag-resource.

ALARM_ARN=$(aws cloudwatch describe-alarms --alarm-names low-test-custom-AlarmTagPropagation \
  --query 'MetricAlarms[0].AlarmArn' --output text)
aws cloudwatch tag-resource --resource-arn "$ALARM_ARN" \
  --tags Key=NotifyRecovery,Value=false
aws cloudwatch list-tags-for-resource --resource-arn "$ALARM_ARN"

On the other hand, to enable tag propagation on an existing alarm, specify ActionConfiguration with put-metric-alarm. Updating with put-metric-alarm overwrites all of the alarm's settings, so if you pass only some of the settings, the items you didn't pass will be lost. I retrieved the current definition with describe-alarms, added only ActionConfiguration to it, and passed that.

Conclusion

This time, I used CloudWatch Alarm tag propagation to make it possible to stop recovery notifications per alarm.

With tag propagation, you can decide whether recovery notifications are needed and the severity in the text through the alarm's tags. A nice point is that you don't need to fix the rule when you add alarms or change whether recovery notifications are needed. When writing it as opt-out, don't forget to include the exists: false condition in addition to anything-but.

I hope this helps someone.

That's all from Yoshida of the Cloud Business Division!

References


そのマルチアカウント運用、気合いで支えていませんか

Organizations や Control Tower で土台は作れても、アカウントもポリシーも増えるほど、運用は「詳しい一人」に寄りかかっていく。属人化が限界を迎える前に、組織として回す仕組み=CCoEへ。5,600社の支援から得た立ち上げの型を、無料資料にまとめました。

CCoE総合支援

組織で回す仕組みの資料をもらう

Share this article

AWSのお困り事はクラスメソッドへ