AWS Health Aware (Ver.2.2.1)のCloudFormation版を組織に導入してみる

AWS Health Aware (Ver.2.2.1)のCloudFormation版を組織に導入してみる

Clock Icon2023.10.10 02:31

AWS Health Aware (以降 AHA)はAWS Healthの通知フレームワークです。

組織(AWS Organizations)やAWSアカウント単体の AWS Health イベントの通知を管理します。 テンプレートを展開するだけで、 Slackチャンネルや Eメール、EventBridge など 各種エンドポイントへの 通知設定を簡単に構築できます。

このAHAを以前にブログで紹介しました。

あれからバージョンも上がったので、再度展開してみます。 最近の Healthのアップデート もあり、特に委任周りで手順が簡素化されています。 そのため、今回は既存AHAを削除して再インストールします。

新しいバージョン(Ver.2.2 以降)の要素も紹介します。

要旨

  • AHAの新しいバージョンについて
    • Version 2.2.1 : Python 3.8 から Python 3.11 に更新
    • Version 2.2 : EventBridge イベントバスへ送られるスキーマを改善
  • AHAの展開方法 in Organizations環境
    • ✅ 管理アカウント上の作業
      • Health Organizational View の有効化
      • AWS Health の委任設定
    • ✅ 委任先メンバーアカウント上の作業
      • 通知先エンドポイント(Slack WebhookやEventBridgeなど)の作成
      • AHAパッケージのS3格納
      • AHAテンプレートの展開

AHAの展開 その1(管理アカウント)

まずは 管理アカウント上 で行う作業を記載します。 すでに実施されている場合は省略できます。

Health Organizational View の有効化

Health Organizational View を有効化します。 AWS Health ページの [組織の状態] → [設定] から有効化できます。

img

AWS Health の委任設定

以下コマンドを実行して、メンバーアカウントに AWS Healthを委任します。

# (注意) ACCOUNT_ID 部分を委任したいメンバーアカウントのIDに置き換えます
aws organizations register-delegated-administrator \
  --account-id ACCOUNT_ID \
  --service-principal health.amazonaws.com

AHAの展開 その2(委任先メンバーアカウント)

次に 委任先メンバーアカウント上 で行う作業を記載します。

通知先のエンドポイントの作成

この設定は 委任先メンバーアカウント上 で行います。

最低一つ、通知先のエンドポイントを作成します。 サポートしているエンドポイントは以下のとおりです。

  • Amazon Chime
  • Slack
  • Microsoft Teams
  • Email
  • EventBridge

今回は EventBridge を使います。 カスタムイベントバス aha-eventbus を作成しました。

img

そして、 aha-eventbus 上に EventBridgeルール catch-all-aha-events を作成しています。 ルールのターゲットに CloudWatchロググループを設定して、 内容を確認できるようにします。

img

AHAテンプレート展開の準備

リポジトリのクローン

AHAリポジトリを一旦ローカルへ落とします。

$ git clone https://github.com/aws-samples/aws-health-aware.git
Cloning into 'aws-health-aware'...
remote: Enumerating objects: 257, done.
remote: Counting objects: 100% (96/96), done.
remote: Compressing objects: 100% (39/39), done.
remote: Total 257 (delta 79), reused 57 (delta 57), pack-reused 161
Receiving objects: 100% (257/257), 1.46 MiB | 15.13 MiB/s, done.
Resolving deltas: 100% (137/137), done.

$ ls
aws-health-aware

パッケージのファイルを圧縮

パッケージのルートにある handler.pymessagegenerator.py を zip圧縮します。 名前を aha-v2.2.1.zip としました。

img

zipファイルのS3格納

aha-v2.2.1.zip を委任先メンバーアカウント上の適当なS3バケットへ格納します。

img

AHAテンプレート展開

パッケージにある CFN_DEPLOY_AHA.yml を CloudFormationスタックとして展開します。

img

スタック名を適当 (AHA-Deployment 等) に入力します。 以下記載のパラメータで、展開しました。

⬇ Customize Alerts/Notifications ~ Package Information

img

パラメータ 参考: デフォルト
AWS Organizations Enabled? Yes No
The types of events to get alerted on (デフォルト値) issue|accountNotification|scheduledChange
Name of S3 Bucket ( aha-v2.2.1.zip ファイルがあるS3バケット)
Name of .zip file in S3 Bucket aha-v2.2.1.zip

⬇ Communication Channels - Slack/Microsoft Teams/Amazon Chime And/or EventBridge

img

パラメータ 参考: デフォルト
Slack Webhook URL (デフォルト値) None
Microsoft Teams Webhook URL (デフォルト値) None
Amazon Chime Webhook URL (デフォルト値) None
EventBusName aha-eventbus None
Email From (デフォルト値) none@domain.com
Email To (デフォルト値) none@domain.com
Subject of Email (デフォルト値) AWS Health Alert

⬇ More Configurations - Optional

img

パラメータ 参考: デフォルト
EventSearchBack (デフォルト値) 1
Which regions to search for events in ap-northeast-1,global all regions
ARN of the AWS Organizations Management Account assume role (if using) (デフォルト値) None
Deploy in secondary region? (デフォルト値) No
Exclude any account numbers? (デフォルト値) None

参考: 展開前の変更セット

img

イベントを確認する

[2023/10/10] 現時点で通知を貰っていないので、貰い次第サンプルとして記載します。

新しい AWS Health Aware の EventBridgeスキーマについて

Ver.2.2 以降のAHAのEventBridgeスキーマは以下のようになっています。

{
    "version": "0",
    "id": "7bf73129-1428-4cd3-a780-95db273d1602",
    "detail-type": "AHA Event",
    "source": "aha",
    "account": "123456789012",
    "time": "2022-07-14T03:56:10Z",
    "region": "region of the eventbus",
    "resources": [
        "i-1234567890abcdef0"
    ],
    "detail": {
        "eventArn": "arn:aws:health:region::event/id",
        "service": "service",
        "eventTypeCode": "typecode",
        "eventTypeCategory": "category",
        "region": "region of the Health event",
        "startTime": "2022-07-02 12:33:26.951000+00:00",
        "endTime": "2022-07-02 12:33:26.951000+00:00",
        "lastUpdatedTime": "2022-07-02 12:36:18.576000+00:00",
        "statusCode": "status",
        "eventScopeCode": "scopecode",
        "eventDescription": {
            "latestDescription": "description"
        },
        "affectedEntities": [{
            "entityValue": "i-1234567890abcdef0",
            "awsAccountId": "account number",
            "awsAccountName": "account name"
        }]
    }
}

Readme for new AHA Event schema より引用

以前のスキーマと比べてフィルタルールを作成しやすいように改善されていますね。 (参考: 過去バージョンのイベントサンプル)

おわりに

以上、新しい AWS Health Aware を組織に導入してみました。

新しい EventBridgeスキーマを活用したい場合や、 内部のPythonバージョンを更新する必要がある場合に参考になれば幸いです。

参考

この記事をシェアする

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.