CloudWatch Anomaly Detection のAPIに追加された AnomalyDetectorId を確認してみた
はじめに
2026年7月10日の AWS CLI v2.35.21 の CHANGELOG で、CloudWatch Anomaly Detection に一意の識別子 AnomalyDetectorId が追加されたことが確認できました。
api-change:cloudwatch: CloudWatch now assigns a unique identifier to each anomaly detector. PutAnomalyDetector and DescribeAnomalyDetectors return this AnomalyDetectorId, which you can use to describe or delete a specific anomaly detector directly.
API では次の3点が変わっています。
| API | 変更内容 |
|---|---|
| PutAnomalyDetector / DescribeAnomalyDetectors | レスポンスに AnomalyDetectorId が含まれるようになった |
| DeleteAnomalyDetector | AnomalyDetectorId を指定して削除できるようになった |
従来、単一メトリクスの Anomaly Detector は Namespace / MetricName / Dimensions / Stat 等の条件を組み合わせて特定する必要がありました。今回のアップデートにより、API レスポンスから AnomalyDetectorId を取得でき、DeleteAnomalyDetector ではその ID を指定して対象を削除できるようになっています。
本記事では、この AnomalyDetectorId が EventBridge の CloudWatch Alarm State Change イベントにも含まれるかを実機で検証しました。
検証内容
検証環境
| 項目 | 値 |
|---|---|
| リージョン | us-east-1 |
| AWS CLI | v2.35.21 |
| 対象メトリクス | AWS/SQS / ApproximateNumberOfMessagesVisible |
| アラーム式 | ANOMALY_DETECTION_BAND(m1, 0.01) |
EventBridge のアラーム状態変更イベントを確認する
以下の構成でアラーム状態変更イベントを取得しました。
ANOMALY_DETECTION_BAND(m1, 0.01)を使う異常検出アラームを作成- EventBridge ルールで
CloudWatch Alarm State Changeイベントを CloudWatch Logs に転送 - アラームの自然遷移および
set-alarm-stateによる強制遷移で計3件のイベントを取得
取得したイベントの結果です。
| イベント | 状態遷移 | 種別 | detail 配下の AnomalyDetectorId |
|---|---|---|---|
| Event 1 | INSUFFICIENT_DATA → OK | 自然遷移 | なし |
| Event 2 | OK → ALARM | set-alarm-state による強制遷移 |
なし |
| Event 3 | ALARM → OK | 自然遷移 | なし |
代表として、自然遷移で取得した Event 1 の detail 配下を示します。
Event 1 の detail 配下
{
"detail": {
"alarmName": "anomaly-detector-id-test-20260714",
"state": {
"value": "OK",
"reason": "Threshold Crossed: no datapoints were received for 1 period and 1 missing datapoint was treated as [NonBreaching].",
"reasonData": "{\"version\":\"1.0\",\"queryDate\":\"2026-07-13T17:49:21.431+0000\",\"period\":60,\"recentDatapoints\":[],\"recentLowerThresholds\":[],\"recentUpperThresholds\":[],\"evaluatedDatapoints\":[{\"timestamp\":\"2026-07-13T17:47:00.000+0000\"}]}",
"timestamp": "2026-07-13T17:49:21.433+0000"
},
"previousState": {
"value": "INSUFFICIENT_DATA",
"reason": "Unchecked: Initial alarm creation",
"timestamp": "2026-07-13T17:49:00.971+0000"
},
"configuration": {
"metrics": [
{
"id": "m1",
"metricStat": {
"metric": {
"namespace": "AWS/SQS",
"name": "ApproximateNumberOfMessagesVisible",
"dimensions": {
"QueueName": "anomaly-detector-id-test-20260714"
}
},
"period": 60,
"stat": "Average"
},
"returnData": true
},
{
"id": "ad1",
"expression": "ANOMALY_DETECTION_BAND(m1, 0.01)",
"label": "ApproximateNumberOfMessagesVisible (Expected)",
"returnData": true
}
]
}
}
}
AnomalyDetectorId フィールドは含まれていませんでした。全3件で同じ結果です。
EventBridge Alarm State Change イベント(全3件)
Event 1: INSUFFICIENT_DATA → OK(自然遷移)
{
"version": "0",
"id": "3f05660b-ea7d-8f82-39a0-f2962aef3b4c",
"detail-type": "CloudWatch Alarm State Change",
"source": "aws.cloudwatch",
"account": "111122223333",
"time": "2026-07-13T17:49:21Z",
"region": "us-east-1",
"resources": [
"arn:aws:cloudwatch:us-east-1:111122223333:alarm:anomaly-detector-id-test-20260714"
],
"detail": {
"alarmName": "anomaly-detector-id-test-20260714",
"state": {
"value": "OK",
"reason": "Threshold Crossed: no datapoints were received for 1 period and 1 missing datapoint was treated as [NonBreaching].",
"reasonData": "{\"version\":\"1.0\",\"queryDate\":\"2026-07-13T17:49:21.431+0000\",\"period\":60,\"recentDatapoints\":[],\"recentLowerThresholds\":[],\"recentUpperThresholds\":[],\"evaluatedDatapoints\":[{\"timestamp\":\"2026-07-13T17:47:00.000+0000\"}]}",
"timestamp": "2026-07-13T17:49:21.433+0000"
},
"previousState": {
"value": "INSUFFICIENT_DATA",
"reason": "Unchecked: Initial alarm creation",
"timestamp": "2026-07-13T17:49:00.971+0000"
},
"configuration": {
"metrics": [
{
"id": "m1",
"metricStat": {
"metric": {
"namespace": "AWS/SQS",
"name": "ApproximateNumberOfMessagesVisible",
"dimensions": {
"QueueName": "anomaly-detector-id-test-20260714"
}
},
"period": 60,
"stat": "Average"
},
"returnData": true
},
{
"id": "ad1",
"expression": "ANOMALY_DETECTION_BAND(m1, 0.01)",
"label": "ApproximateNumberOfMessagesVisible (Expected)",
"returnData": true
}
]
}
}
}
Event 2: OK → ALARM(set-alarm-state による強制遷移)
{
"version": "0",
"id": "90a4063c-9e65-2079-e6dd-f8d7b3998d15",
"detail-type": "CloudWatch Alarm State Change",
"source": "aws.cloudwatch",
"account": "111122223333",
"time": "2026-07-13T17:54:26Z",
"region": "us-east-1",
"resources": [
"arn:aws:cloudwatch:us-east-1:111122223333:alarm:anomaly-detector-id-test-20260714"
],
"detail": {
"alarmName": "anomaly-detector-id-test-20260714",
"state": {
"value": "ALARM",
"reason": "Forced for testing: checking if AnomalyDetectorId appears in EventBridge payload",
"timestamp": "2026-07-13T17:54:26.164+0000"
},
"previousState": {
"value": "OK",
"reason": "Threshold Crossed: no datapoints were received for 1 period and 1 missing datapoint was treated as [NonBreaching].",
"reasonData": "{\"version\":\"1.0\",\"queryDate\":\"2026-07-13T17:49:21.431+0000\",\"period\":60,\"recentDatapoints\":[],\"recentLowerThresholds\":[],\"recentUpperThresholds\":[],\"evaluatedDatapoints\":[{\"timestamp\":\"2026-07-13T17:47:00.000+0000\"}]}",
"timestamp": "2026-07-13T17:49:21.433+0000"
},
"configuration": {
"metrics": [
{
"id": "m1",
"metricStat": {
"metric": {
"namespace": "AWS/SQS",
"name": "ApproximateNumberOfMessagesVisible",
"dimensions": {
"QueueName": "anomaly-detector-id-test-20260714"
}
},
"period": 60,
"stat": "Average"
},
"returnData": true
},
{
"id": "ad1",
"expression": "ANOMALY_DETECTION_BAND(m1, 0.01)",
"label": "ApproximateNumberOfMessagesVisible (Expected)",
"returnData": true
}
]
}
}
}
Event 3: ALARM → OK(自然遷移)
{
"version": "0",
"id": "8f97e3d5-77ae-ad1c-f246-2822d26f3518",
"detail-type": "CloudWatch Alarm State Change",
"source": "aws.cloudwatch",
"account": "111122223333",
"time": "2026-07-13T17:55:48Z",
"region": "us-east-1",
"resources": [
"arn:aws:cloudwatch:us-east-1:111122223333:alarm:anomaly-detector-id-test-20260714"
],
"detail": {
"alarmName": "anomaly-detector-id-test-20260714",
"state": {
"value": "OK",
"reason": "Threshold Crossed: no datapoints were received for 1 period and 1 missing datapoint was treated as [NonBreaching].",
"reasonData": "{\"version\":\"1.0\",\"queryDate\":\"2026-07-13T17:55:48.076+0000\",\"period\":60,\"recentDatapoints\":[],\"recentLowerThresholds\":[],\"recentUpperThresholds\":[],\"evaluatedDatapoints\":[{\"timestamp\":\"2026-07-13T17:53:00.000+0000\"}]}",
"timestamp": "2026-07-13T17:55:48.077+0000"
},
"previousState": {
"value": "ALARM",
"reason": "Forced for testing: checking if AnomalyDetectorId appears in EventBridge payload",
"timestamp": "2026-07-13T17:54:26.164+0000"
},
"configuration": {
"metrics": [
{
"id": "m1",
"metricStat": {
"metric": {
"namespace": "AWS/SQS",
"name": "ApproximateNumberOfMessagesVisible",
"dimensions": {
"QueueName": "anomaly-detector-id-test-20260714"
}
},
"period": 60,
"stat": "Average"
},
"returnData": true
},
{
"id": "ad1",
"expression": "ANOMALY_DETECTION_BAND(m1, 0.01)",
"label": "ApproximateNumberOfMessagesVisible (Expected)",
"returnData": true
}
]
}
}
}
API レスポンスで AnomalyDetectorId を確認する
PutAnomalyDetector のレスポンスで AnomalyDetectorId が返ることを確認します。
aws cloudwatch put-anomaly-detector \
--single-metric-anomaly-detector '{
"Namespace": "AWS/SQS",
"MetricName": "ApproximateNumberOfMessagesVisible",
"Dimensions": [{"Name": "QueueName", "Value": "anomaly-detector-id-test-20260714-v2"}],
"Stat": "Average"
}' \
--region us-east-1
{
"AnomalyDetectorId": "BB31037C6C9FD22A74043214A57CE8DB-Average-60-None"
}
DescribeAnomalyDetectors でも同じ ID が返ることを確認しました。
aws cloudwatch describe-anomaly-detectors --region us-east-1
{
"AnomalyDetectors": [
{
"AnomalyDetectorId": "BB31037C6C9FD22A74043214A57CE8DB-Average-60-None",
"Namespace": "AWS/SQS",
"MetricName": "ApproximateNumberOfMessagesVisible",
"Dimensions": [
{
"Name": "QueueName",
"Value": "anomaly-detector-id-test-20260714-v2"
}
],
"Stat": "Average",
"Configuration": {
"ExcludedTimeRanges": []
},
"StateValue": "PENDING_TRAINING",
"SingleMetricAnomalyDetector": {
"AccountId": "111122223333",
"Namespace": "AWS/SQS",
"MetricName": "ApproximateNumberOfMessagesVisible",
"Dimensions": [
{
"Name": "QueueName",
"Value": "anomaly-detector-id-test-20260714-v2"
}
],
"Stat": "Average"
}
}
]
}
まとめ
多数の異常検出アラームを運用している環境では、発報後に対象の Anomaly Detector を特定し、しきい値や検出設定を調整する作業が必要となることがあります。異常検出の通知に AnomalyDetectorId が含まれれば、発生源の特定が捗ることが期待できます。
記事執筆時点では、EventBridge の CloudWatch Alarm State Change イベントには AnomalyDetectorId は含まれていませんでしたが、今後のイベントペイロードへの追加に期待したいと思います。







