本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用 建立儀表板 AWS CLI
本節說明如何使用 create-dashboard命令來建立自訂儀表板或 Highlights 儀表板。
使用 時 AWS CLI,請記住您的命令會在為設定檔 AWS 區域 設定的 中執行。如果您想在不同區域中執行命令,則可變更設定檔的預設區域,或搭配 --region 參數使用命令。
CloudTrail 在手動或排程重新整理期間執行查詢以填入儀表板的小工具。必須授予 CloudTrail 許可,才能在與儀表板小工具相關聯的每個事件資料存放區上執行 StartQuery操作。若要提供許可,請執行 put-resource-policy命令,將資源型政策連接至每個事件資料存放區,或在 CloudTrail 主控台上編輯事件資料存放區的政策。如需政策範例,請參閱 範例:允許 CloudTrail 執行查詢以重新整理儀表板。
若要設定重新整理排程, CloudTrail 必須授予執行 StartDashboardRefresh操作的許可,才能代表您重新整理儀表板。若要提供許可,請執行 put-resource-policy操作,將資源型政策連接至儀表板,或在 CloudTrail 主控台上編輯儀表板的政策。如需政策範例,請參閱 儀表板的資源型政策範例。
使用 建立自訂儀表板 AWS CLI
下列程序說明如何建立自訂儀表板、將所需的資源型政策連接至事件資料存放區和儀表板,以及更新儀表板以設定和啟用重新整理排程。
-
執行
create-dashboard以建立儀表板。建立自訂儀表板時,您最多可以傳入 10 個小工具的陣列。小工具提供查詢結果的圖形表示。每個小工具都包含
ViewProperties、QueryStatement和QueryParameters。-
ViewProperties– 指定檢視類型的屬性。如需詳細資訊,請參閱檢視小工具的屬性。 -
QueryStatement– 儀表板重新整理時CloudTrail 執行的查詢。只要事件資料存放區存在於您的帳戶中,您就可以跨多個事件資料存放區進行查詢。 -
QueryParameters– 自訂儀表板支援下列QueryParameters值:$Period$、$StartTime$和$EndTime$。若要使用 ,請在QueryStatement您要取代 參數的?中QueryParameters放置 。執行查詢時,CloudTrail 會填入參數。
下列範例會建立具有四個小工具的儀表板,每個檢視類型之一。
注意
在此範例中,
?被單引號包圍,因為它與 搭配使用eventTime。根據您執行的作業系統,您可能需要使用逸出引號括住單引號。如需詳細資訊,請參閱 中的使用引號和常值搭配字串 AWS CLI。aws cloudtrail create-dashboard --name AccountActivityDashboard \ --widgets '[ { "ViewProperties": { "Height": "2", "Width": "4", "Title": "TopErrors", "View": "Table" }, "QueryStatement": "SELECT errorCode, COUNT(*) AS eventCount FROM eds WHERE eventTime > '?' AND eventTime < '?' AND (errorCode is not null) GROUP BY errorCode ORDER BY eventCount DESC LIMIT 100", "QueryParameters": ["$StartTime$", "$EndTime$"] }, { "ViewProperties": { "Height": "2", "Width": "4", "Title": "MostActiveRegions", "View": "PieChart", "LabelColumn": "awsRegion", "ValueColumn": "eventCount", "FilterColumn": "awsRegion" }, "QueryStatement": "SELECT awsRegion, COUNT(*) AS eventCount FROM eds where eventTime > '?' and eventTime < '?' GROUP BY awsRegion ORDER BY eventCount LIMIT 100", "QueryParameters": ["$StartTime$", "$EndTime$"] }, { "ViewProperties": { "Height": "2", "Width": "4", "Title": "AccountActivity", "View": "LineChart", "YAxisColumn": "eventCount", "XAxisColumn": "eventDate", "FilterColumn": "readOnly" }, "QueryStatement": "SELECT DATE_TRUNC('?', eventTime) AS eventDate, IF(readOnly, 'read', 'write') AS readOnly, COUNT(*) as eventCount FROM eds WHERE eventTime > '?' AND eventTime < '?' GROUP BY DATE_TRUNC('?', eventTime), readOnly ORDER BY DATE_TRUNC('?', eventTime), readOnly", "QueryParameters": ["$Period$", "$StartTime$", "$EndTime$", "$Period$", "$Period$"] }, { "ViewProperties": { "Height": "2", "Width": "4", "Title": "TopServices", "View": "BarChart", "LabelColumn": "service", "ValueColumn": "eventCount", "FilterColumn": "service", "Orientation": "Horizontal" }, "QueryStatement": "SELECT REPLACE(eventSource, '.amazonaws.com') AS service, COUNT(*) AS eventCount FROM eds WHERE eventTime > '?' AND eventTime < '?' GROUP BY eventSource ORDER BY eventCount DESC LIMIT 100", "QueryParameters": ["$StartTime$", "$EndTime$"] } ]' -
建立個別檔案,其中包含小工具 中每個事件資料存放區所需的資源政策
QueryStatement。使用下列範例政策陳述式命名檔案policy.json:將
123456789012取代為您的帳戶 ID,arn:aws:cloudtrail:us-east-1:123456789012:dashboard/exampleDashboard取代為儀表板的 ARN。如需儀表板資源型政策的詳細資訊,請參閱 範例:允許 CloudTrail 執行查詢以重新整理儀表板。
-
執行
put-resource-policy命令來連接政策。您也可以在 CloudTrail 主控台上更新事件資料存放區的資源型政策。下列範例會將資源型政策連接至事件資料存放區。
aws cloudtrail put-resource-policy \ --resource-arneds-arn\ --resource-policy file://policy.json -
執行
put-resource-policy命令,將資源型政策連接至儀表板。如需政策範例,請參閱 儀表板的資源型政策範例。下列範例會將資源型政策連接至儀表板。將
account-id取代為您的帳戶 ID,將dashboard-arn取代為儀表板的 ARN。aws cloudtrail put-resource-policy \ --resource-arndashboard-arn\ --resource-policy '{"Version": "2012-10-17", "Statement": [{"Sid": "DashboardPolicy", "Effect": "Allow", "Principal": { "Service": "cloudtrail.amazonaws.com" }, "Action": "cloudtrail:StartDashboardRefresh", "Condition": { "StringEquals": { "AWS:SourceArn": "dashboard-arn", "AWS:SourceAccount": "account-id"}}}]}' -
執行
update-dashboard命令,透過設定--refresh-schedule參數來設定和啟用重新整理排程。--refresh-schedule包含下列選用參數:-
Frequency– 排程Value的Unit和 。對於自訂儀表板,單位可以是
HOURS或DAYS。對於自訂儀表板,當單位為
1、、6、 時12,以下值有效HOURS:24對於自訂儀表板,單位
DAYS為 時的唯一有效值1。 -
Status– 指定是否啟用重新整理排程。將值設定為ENABLED以啟用重新整理排程,或設定為DISABLED以關閉重新整理排程。 -
TimeOfDay– 一天中執行排程的時間,每小時僅參考分鐘;預設值為 00:00。
下列範例會設定每六小時的重新整理排程,並啟用排程。
aws cloudtrail update-dashboard --dashboard-id AccountActivityDashboard \ --refresh-schedule '{"Frequency": {"Unit": "HOURS", "Value": 6}, "Status": "ENABLED"}' -
使用 啟用反白儀表板 AWS CLI
下列程序說明如何建立反白儀表板、將所需的資源型政策連接至事件資料存放區和儀表板,以及更新儀表板以設定和啟用重新整理排程。
-
執行
create-dashboard命令來建立 Highlights 儀表板。若要建立此儀表板,--name必須是AWSCloudTrail-Highlights。aws cloudtrail create-dashboard --name AWSCloudTrail-Highlights -
針對您帳戶中的每個事件資料存放區,執行
put-resource-policy命令,將資源型政策連接至事件資料存放區。您也可以在 CloudTrail 主控台上更新事件資料存放區的資源型政策。如需政策範例,請參閱 範例:允許 CloudTrail 執行查詢以重新整理儀表板。下列範例會將資源型政策連接至事件資料存放區。將
account-id取代為您的帳戶 ID、將eds-arn取代為事件資料存放區的 ARN,並將dashboard-arn取代為儀表板的 ARN。aws cloudtrail put-resource-policy \ --resource-arneds-arn\ --resource-policy '{"Version": "2012-10-17", "Statement": [{"Sid": "EDSPolicy", "Effect": "Allow", "Principal": { "Service": "cloudtrail.amazonaws.com" }, "Action": "cloudtrail:StartQuery", "Condition": { "StringEquals": { "AWS:SourceArn": "dashboard-arn", "AWS:SourceAccount": "account-id"}}} ]}' -
執行
put-resource-policy命令,將資源型政策連接至儀表板。如需政策範例,請參閱 儀表板的資源型政策範例。下列範例會將資源型政策連接至儀表板。將
account-id取代為您的帳戶 ID,將dashboard-arn取代為儀表板的 ARN。aws cloudtrail put-resource-policy \ --resource-arndashboard-arn\ --resource-policy '{"Version": "2012-10-17", "Statement": [{"Sid": "DashboardPolicy", "Effect": "Allow", "Principal": { "Service": "cloudtrail.amazonaws.com" }, "Action": "cloudtrail:StartDashboardRefresh", "Condition": { "StringEquals": { "AWS:SourceArn": "dashboard-arn", "AWS:SourceAccount": "account-id"}}}]}' -
執行
update-dashboard命令,透過設定--refresh-schedule參數來設定和啟用重新整理排程。對於醒目提示儀表板,唯一有效的UNIT是HOURS,唯一有效的Value是6。aws cloudtrail update-dashboard --dashboard-id AWSCloudTrail-Highlights \ --refresh-schedule '{"Frequency": {"Unit": "HOURS", "Value": 6}, "Status": "ENABLED"}'