本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用 記錄 Insights 事件 AWS CLI
您可以使用 AWS CLI設定您的追蹤和事件資料存放區,以記錄 Insights 事件。
注意
若要在 API 呼叫率上記錄 Insights 事件,追蹤或事件資料存放區必須記錄write管理事件。若要以 API 錯誤率記錄 Insights 事件,追蹤或事件資料存放區必須記錄read或write管理事件。
使用 記錄線索的 Insights 事件 AWS CLI
若要傳回線索的目前 Insights 選擇器,請執行 get-insight-selectors命令。
aws cloudtrail get-insight-selectors --trail-nameTrailName
下列範例回應顯示名為 之線索的 Insights 選擇器insights-trail。
{ "TrailARN": "arn:aws:cloudtrail:us-east-1:123456789012:trail/insights-trail", "InsightSelectors": [ { "InsightType": "ApiCallRateInsight" }, { "InsightType": "ApiErrorRateInsight" } ] }
如果追蹤未啟用 Insights,get-insight-selectors命令會傳回下列錯誤訊息:「呼叫 GetInsightSelectors 操作時發生錯誤 (InsightNotEnabledException):Trail arn:aws:cloudtrail:us-east-1:123456789012:trail/trailName 未啟用 Insights。Edit the trail settings to enable Insights, and then try the operation again." (呼叫 GetInsightSelectors 操作時,發生錯誤 (InsightNotEnabledException):追蹤名稱未啟用 Insights。編輯追蹤設定以啟用 Insights,然後再試一次操作。)
若要設定您的追蹤記錄 Insights 事件,請執行 put-insight-selectors 命令。下面的範例顯示如何設定追蹤以包含 Insights 事件。Insights 選取器值可以是 ApiCallRateInsight 或 ApiErrorRateInsight (或兩者)。
aws cloudtrail put-insight-selectors --trail-nameTrailName--insight-selectors '[{"InsightType": "ApiCallRateInsight"},{"InsightType": "ApiErrorRateInsight"}]'
下列結果顯示針對追蹤設定的 Insights 事件選取器。
{ "TrailARN": "arn:aws:cloudtrail:us-east-1:123456789012:trail/TrailName", "InsightSelectors": [ { "InsightType": "ApiErrorRateInsight" }, { "InsightType": "ApiCallRateInsight" } ] }
使用 記錄事件資料存放區的 Insights 事件 AWS CLI
若要在事件資料存放區上啟用 Insights 事件,您需要擁有會記錄管理事件的來源事件資料存放區和會記錄 Insights 事件的目的地事件資料存放區。
若要檢視是否在事件資料存放區上啟用 Insights 事件,請執行 get-insight-selectors 命令。
aws cloudtrail get-insight-selectors --event-data-store arn:aws:cloudtrail:us-east-1:123456789012:eventdatastore/EXAMPLE-f852-4e8f-8bd1-bcf6cEXAMPLE
若要檢視事件資料存放區是否設定為接收 Insights 事件或管理事件,請執行 get-event-data-store 命令。
aws cloudtrail get-event-data-store --event-data-store arn:aws:cloudtrail:us-east-1:123456789012:eventdatastore/EXAMPLE-d483-5c7d-4ac2-adb5dEXAMPLE
如果事件資料存放區設定為接收 Insights 事件,eventCategory則會將其設定為 Insight。
以下程序將向您說明如何建立目的地和來源事件資料存放區,然後啟用 Insights 事件。
-
執行 aws cloudtrail create-event-data-store
命令來建立會收集 Insights 事件的目的地事件資料存放區。 eventCategory的值必須為Insight。使用您希望在事件資料存放區中保留事件的天數來替換retention-period-days。若您要用 AWS Organizations 組織的管理帳戶登入,請加入
--organization-enabled參數 (如果您希望向委派的管理員授予存取事件資料存放區的權限)。aws cloudtrail create-event-data-store \ --name insights-event-data-store \ --no-multi-region-enabled \ --retention-periodretention-period-days\ --advanced-event-selectors '[ { "Name": "Select Insights events", "FieldSelectors": [ { "Field": "eventCategory", "Equals": ["Insight"] } ] } ]'以下是回應範例。
{ "Name": "insights-event-data-store", "ARN": "arn:aws:cloudtrail:us-east-1:111122223333:eventdatastore/EXAMPLEf852-4e8f-8bd1-bcf6cEXAMPLE", "AdvancedEventSelectors": [ { "Name": "Select Insights events", "FieldSelectors": [ { "Field": "eventCategory", "Equals": [ "Insight" ] } ] } ], "MultiRegionEnabled": false, "OrganizationEnabled": false, "BillingMode": "EXTENDABLE_RETENTION_PRICING", "RetentionPeriod": "90", "TerminationProtectionEnabled": true, "CreatedTimestamp": "2023-11-08T15:22:33.578000+00:00", "UpdatedTimestamp": "2023-11-08T15:22:33.714000+00:00" }您將使用來自回應的
ARN(或 ARN 的 ID 尾碼),作為步驟 3 中--insights-destination參數的值。 -
執行 aws cloudtrail create-event-data-store
命令以建立記錄管理事件的來源事件資料存放區。依預設,事件資料存放區會記錄所有管理事件。如果想要記錄所有管理事件,您不需要指定進階事件選取器。使用您希望在事件資料存放區中保留事件的天數來替換 retention-period-days。若您要建立組織事件資料存放區,請加入--organization-enabled參數。aws cloudtrail create-event-data-store --name source-event-data-store --retention-periodretention-period-days以下是回應範例。
{ "EventDataStoreArn": "arn:aws:cloudtrail:us-east-1:111122223333:eventdatastore/EXAMPLE9952-4ab9-49c0-b788-f4f3EXAMPLE", "Name": "source-event-data-store", "Status": "CREATED", "AdvancedEventSelectors": [ { "Name": "Default management events", "FieldSelectors": [ { "Field": "eventCategory", "Equals": [ "Management" ] } ] } ], "MultiRegionEnabled": true, "OrganizationEnabled": false, "BillingMode": "EXTENDABLE_RETENTION_PRICING", "RetentionPeriod": 90, "TerminationProtectionEnabled": true, "CreatedTimestamp": "2023-11-08T15:25:35.578000+00:00", "UpdatedTimestamp": "2023-11-08T15:25:35.714000+00:00" }您將使用來自回應的
ARN(或 ARN 的 ID 尾碼),作為步驟 3 中--event-data-store參數的值。 -
執行 put-insight-selectors
命令以啟用 Insights 事件。Insights 選取器值可以是 ApiCallRateInsight或ApiErrorRateInsight(或兩者)。對於--event-data-store參數,指定來源事件資料存放區的 ARN (或 ARN 的 ID 尾碼),該存放區會記錄管理事件並且將啟用 Insights。對於--insights-destination參數,指定目的地事件資料存放區的 ARN (或 ARN 的 ID 尾碼),該存放區將會記錄 Insights 事件。aws cloudtrail put-insight-selectors --event-data-store arn:aws:cloudtrail:us-east-1:111122223333:eventdatastore/EXAMPLE9952-4ab9-49c0-b788-f4f3EXAMPLE --insights-destination arn:aws:cloudtrail:us-east-1:111122223333:eventdatastore/EXAMPLEf852-4e8f-8bd1-bcf6cEXAMPLE --insight-selectors '[{"InsightType": "ApiCallRateInsight"},{"InsightType": "ApiErrorRateInsight"}]'下列結果顯示針對事件資料存放區設定的 Insights 事件選取器。
{ "EventDataStoreARN": "arn:aws:cloudtrail:us-east-1:111122223333:eventdatastore/EXAMPLE9952-4ab9-49c0-b788-f4f3EXAMPLE", "InsightsDestination": "arn:aws:cloudtrail:us-east-1:111122223333:eventdatastore/EXAMPLEf852-4e8f-8bd1-bcf6cEXAMPLE", "InsightSelectors": [ { "InsightType": "ApiErrorRateInsight" }, { "InsightType": "ApiCallRateInsight" } ] }
在您第一次在事件資料存放區上啟用 CloudTrail Insights 之後,CloudTrail 最多可能需要 7 天才能開始交付 Insights 事件,前提是在此期間偵測到異常活動。