cdk acknowledge でAWS CDKの通知メッセージを抑制する
どうも!オペ部の西村祐二です!
CDK CLI でコマンドを実行するたびに表示される通知(NOTICES)が気になり、抑制する方法を調べたのでまとめておきます。
結論 (先に解決方法)
通知を抑制する方法はいくつかありますが、警告メッセージ自体に記載されている cdk acknowledge コマンドで個別に非表示にするのが良いかなと思いました。確認済みの通知だけを抑制できるので、重要な通知を見逃しにくいのもポイントです。
実行すると cdk.context.json に acknowledged-issue-numbers が追加され、以降その通知は表示されなくなります。
cdk acknowledge <通知のID>
遭遇した通知
CDK CLI には、セキュリティ脆弱性やリグレッションなどの重要な情報を NOTICES としてコマンド実行時に自動表示する仕組みがあります。
cdk synth や cdk deploy を実行すると、コマンド出力の末尾に以下の通知が毎回表示されていました。
NOTICES (What's this? https://github.com/aws/aws-cdk/wiki/CLI-Notices)
34892 CDK CLI will collect telemetry data on command usage starting at version 2.1100.0 (unless opted out)
Overview: We do not collect customer content and we anonymize the
telemetry we do collect. See the attached issue for more
information on what data is collected, why, and how to
opt-out. Telemetry will NOT be collected for any CDK CLI
version prior to version 2.1100.0 - regardless of
opt-in/out. You can also preview the telemetry we will start
collecting by logging it to a local file, by adding
`--unstable=telemetry --telemetry-file=my/local/file` to any
`cdk` command.
Affected versions: cli: >=2.0.0 <2.1100.0
More information at: https://github.com/aws/aws-cdk/issues/34892
If you don't want to see a notice anymore, use "cdk acknowledge <id>". For example, "cdk acknowledge 34892".
これは CDK CLI v2.1100.0 からテレメトリデータの収集を開始するという告知(Issue #34892)です。内容を確認したうえで、毎回表示されるのは不要なので抑制することにしました。
環境:
- CDK CLI: 2.1023.0
解決方法の詳細
cdk acknowledge コマンドを実行する
CDK プロジェクトのルートディレクトリ(cdk.json が存在するディレクトリ)で、通知メッセージの末尾に記載されている cdk acknowledge コマンドに通知の ID を渡して実行します。
cdk acknowledge 34892
実行すると、プロジェクトの cdk.context.json に以下の内容が追加されます。cdk.context.json は CDK が自動生成するファイルで、プロジェクトによっては .gitignore に含まれている場合があります。チームで acknowledge の状態を共有したい場合は、cdk.context.json がリポジトリに含まれているか確認してください。
{
"acknowledged-issue-numbers": [
34892
]
}
この状態で cdk synth などを実行すると、該当の通知が表示されなくなります。
試してみた
サンプルプロジェクトを作成して、通知の表示から抑制までの流れを確認してみます。
1. サンプルプロジェクトを作成する
mkdir cdk-notice-test && cd cdk-notice-test
cdk init app --language typescript
2. cdk synth で通知が表示されることを確認する
cdk synth
コマンド出力の末尾に NOTICES が表示されます。
NOTICES (What's this? https://github.com/aws/aws-cdk/wiki/CLI-Notices)
34892 CDK CLI will collect telemetry data on command usage starting at version 2.1100.0 (unless opted out)
Overview: We do not collect customer content and we anonymize the
telemetry we do collect. See the attached issue for more
information on what data is collected, why, and how to
opt-out. Telemetry will NOT be collected for any CDK CLI
version prior to version 2.1100.0 - regardless of
opt-in/out.
Affected versions: cli: >=2.0.0 <2.1100.0
More information at: https://github.com/aws/aws-cdk/issues/34892
If you don't want to see a notice anymore, use "cdk acknowledge <id>". For example, "cdk acknowledge 34892".
3. cdk acknowledge で通知を抑制する
cdk acknowledge 34892
実行後、cdk.context.json に acknowledged-issue-numbers が追加されていることを確認します。
cat cdk.context.json
{
"acknowledged-issue-numbers": [
34892
]
}
4. 再度 cdk synth で通知が消えたことを確認する
cdk synth
今度はコマンド出力の末尾に NOTICES が表示されなくなりました。
通知を抑制する他の方法
cdk acknowledge 以外にも通知を抑制する方法があります。
--no-notices オプション
コマンド実行時に --no-notices を付けると、その実行に限りすべての通知が非表示になります。
cdk synth --no-notices
cdk deploy --no-notices
cdk.json で notices: false を設定
公式ドキュメントでは、cdk.json に "notices": false を追加するとプロジェクト全体で通知が非表示になると記載されています。
{
"app": "npx ts-node --prefer-ts-exts bin/my-app.ts",
"notices": false,
"context": {}
}
方法の比較
| 方法 | 範囲 | 対象 |
|---|---|---|
cdk acknowledge <ID> |
プロジェクト単位 | 指定した通知のみ |
--no-notices |
コマンド実行ごと | すべての通知 |
notices: false |
プロジェクト全体 | すべての通知 |
cdk acknowledge は確認済みの通知だけを個別に非表示にできるため、セキュリティ関連など重要な通知を見逃すリスクが少ないです。一方、--no-notices や notices: false はすべての通知を一括で非表示にするため、重要な通知も見逃す可能性があります。
まとめ
- CDK CLI の通知は cdk acknowledge コマンドで個別に抑制できる
- 実行すると
cdk.context.jsonのacknowledged-issue-numbersに ID が追加される - すべての通知を一括で非表示にしたい場合は
--no-noticesオプションまたはcdk.jsonのnotices: falseを使う
個人的にはcdk acknowledgeで個別に対応するほうが、重要な通知を見逃しにくいのでオススメかなと感じました。
誰かの参考になれば幸いです。
関連リンク:







