Patch Manager の EventBridge 通知でスキャンとインストールを判別するにはどうすればいいですか

Patch Manager の EventBridge 通知でスキャンとインストールを判別するにはどうすればいいですか

AWS Patch Manager のスキャンとインストール完了を区別して EventBridge で通知する方法について紹介します。EC2 Command Invocation Status-change Notification では判別できない理由と、Maintenance Window Task Target Invocation State-change Notification を使った解決策を解説します。
2026.07.30

困っていた内容

AWS Systems Manager Patch Manager を利用しており、スキャン用とインストール用の 2 つのメンテナンスウィンドウをそれぞれ作成しています。

現在は EventBridge を使って Patch Manager の実行完了通知を受け取っています。
ただ、EC2 Command Invocation Status-change Notification イベントにはスキャンとインストールを判別できる情報が含まれていないため、インストール完了時のみ通知する設定ができません。
EventBridge ルールでスキャンとインストールを判別する方法を知りたいです。

どう対応すればいいの?

EC2 Command Invocation Status-change Notification に代えて、Maintenance Window Task Target Invocation State-change Notification イベントを利用することで、メンテナンスウィンドウ単位でフィルタリングできます。

EC2 Command Invocation Status-change Notification イベントについて

EC2 Command Invocation Status-change Notification イベントは、SSM Run Command のインスタンスレベルのステータス変化を通知するイベントです。
このイベントのペイロードには document-name や instance-id、status などが含まれますが、コマンドのパラメーター(Operation: Scan / Install を示すフィールドなど)は含まれません。

https://docs.aws.amazon.com/ja_jp/systems-manager/latest/userguide/monitoring-systems-manager-event-examples.html#SSM-Run-Command-event-types

{
    "version": "0",
    "id": "4780e1b8-f56b-4de5-95f2-95dbEXAMPLE",
    "detail-type": "EC2 Command Invocation Status-change Notification",
    "source": "aws.ssm",
    "account": "123456789012",
    "time": "2024-07-10T21:51:32Z",
    "region": "us-east-2",
    "resources": ["arn:aws:ec2:us-east-2:123456789012:instance/i-02573cafcfEXAMPLE"],
    "detail": {
        "command-id": "e8d3c0e4-71f7-4491-898f-c9b35bee5f3b",
        "document-name": "AWS-RunPowerShellScript",
        "instance-id": "i-02573cafcfEXAMPLE",
        "requested-date-time": "2024-07-10T21:51:30.049Z",
        "status": "Success"
    }
}

そのため、このイベントタイプのみでスキャンとインストールを区別することは困難です。

Maintenance Window Task Target Invocation State-change Notification イベントを使った対処方法

メンテナンスウィンドウのタスク実行状態の変化を通知する Maintenance Window Task Target Invocation State-change Notification イベントには window-id フィールドが含まれます。

https://docs.aws.amazon.com/ja_jp/systems-manager/latest/userguide/monitoring-systems-manager-event-examples.html#EC2_maintenance_windows_event_types

{
   "version":"0",
   "id":"01234567-0123-0123-0123-0123456789ab",
   "detail-type":"Maintenance Window Task Target Invocation State-change Notification",
   "source":"aws.ssm",
   "account":"123456789012",
   "time":"2025-06-02T14:52:18Z",
   "region":"us-east-2",
   "resources":[
      "arn:aws:ssm:us-east-2:123456789012:maintenancewindow/mw-123456789012345678"
   ],
   "detail":{
      "start-time":"2025-06-02T14:48:28.039273Z",
      "end-time":"2025-06-02T14:52:18.083773Z",
      "window-id":"mw-0ed7251d3fcf6e0c2",
      "window-execution-id":"791b72e0-f0da-4021-8b35-f95dfEXAMPLE",
      "task-execution-id":"c9b05aba-197f-4d8d-be34-e73fbEXAMPLE",
      "window-target-id":"e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE",
      "status":"SUCCESS",
      "owner-information":"Owner"
   }
}

また、このイベントタイプの status フィールドには IN_PROGRESS / SUCCESS / FAILED / TIMED_OUT が入ります。

https://docs.aws.amazon.com/ja_jp/systems-manager/latest/userguide/monitoring-systems-manager-event-examples.html#EC2_maintenance_windows_event_types

有効なステータス値は、IN_PROGRESS、SUCCESS、FAILED および TIMED_OUT です。

そのため、インストール用のメンテナンスウィンドウ ID が mw-0123456789abcdef0 であれば、EventBridge ルールのイベントパターンを次のように設定することでインストールのイベントのみを絞り込めます。
status に終了状態(SUCCESS / FAILED / TIMED_OUT)を指定することで、タスクの完了時のみ通知を受け取れます。

{
  "source": ["aws.ssm"],
  "detail-type": ["Maintenance Window Task Target Invocation State-change Notification"],
  "detail": {
    "window-id": ["mw-0123456789abcdef0"],
    "status": ["SUCCESS", "FAILED", "TIMED_OUT"]
  }
}

なお、スキャン用のメンテナンスウィンドウには別の window-id が割り当てられているため、上記のようにしてインストール用の window-id だけを指定することでフィルタリングできます。

参考情報

https://docs.aws.amazon.com/ja_jp/systems-manager/latest/userguide/monitoring-systems-manager-event-examples.html

https://docs.aws.amazon.com/ja_jp/systems-manager/latest/userguide/monitoring-eventbridge-events.html


AWSテクニカルサポートノートについて

過去にクラスメソッドのAWS総合支援サービスで頂いたお問合せの中から、通常のAWS利用時でも有益になりうる情報をテクニカルサポートチームがTIPSとしてご紹介しています。技術サポートは、無料でご提供しております。詳細は下記ボタンからご覧ください。

クラスメソッドのAWSサポートの詳細を見る

この記事をシェアする

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

関連記事