

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用 建立儀表板 AWS CLI
<a name="lake-dashboard-cli-create"></a>

本節說明如何使用 `create-dashboard`命令來建立自訂儀表板或反白儀表板。

使用 時 AWS CLI，請記住您的命令會在為設定檔 AWS 區域 設定的 中執行。如果您想在不同區域中執行命令，則可變更設定檔的預設區域，或搭配 `--region` 參數使用命令。

 CloudTrail 在手動或排程重新整理期間執行查詢以填入儀表板的小工具。必須授予 CloudTrail 許可，才能在與儀表板小工具相關聯的每個事件資料存放區上執行 `StartQuery`操作。若要提供許可，請執行 `put-resource-policy`命令，將資源型政策連接到每個事件資料存放區，或在 CloudTrail 主控台上編輯事件資料存放區的政策。如需政策範例，請參閱 [範例：允許 CloudTrail 執行查詢以重新整理儀表板](security_iam_resource-based-policy-examples.md#security_iam_resource-based-policy-examples-eds-dashboard)。

 若要設定重新整理排程， CloudTrail 必須授予執行 `StartDashboardRefresh`操作的許可，才能代表您重新整理儀表板。若要提供許可，請執行 `put-resource-policy`操作，將資源型政策連接至儀表板，或在 CloudTrail 主控台上編輯儀表板的政策。如需政策範例，請參閱 [儀表板的資源型政策範例](security_iam_resource-based-policy-examples.md#security_iam_resource-based-policy-examples-dashboards)。

**Topics**
+ [使用 建立自訂儀表板 AWS CLI](#lake-dashboard-cli-create-custom)
+ [使用 啟用反白儀表板 AWS CLI](#lake-dashboard-cli-create-highlights)
+ [檢視小工具的屬性](lake-widget-properties.md)

## 使用 建立自訂儀表板 AWS CLI
<a name="lake-dashboard-cli-create-custom"></a>

下列程序說明如何建立自訂儀表板、將所需的資源型政策連接至事件資料存放區和儀表板，以及更新儀表板以設定和啟用重新整理排程。

1. 執行 `create-dashboard` 以建立儀表板。

   建立自訂儀表板時，您最多可以傳入 10 個小工具的陣列。小工具提供查詢結果的圖形表示。每個小工具都包含 `ViewProperties`、 `QueryStatement`和 `QueryParameters`。
   + `ViewProperties` – 指定檢視類型的屬性。如需詳細資訊，請參閱[檢視小工具的屬性](lake-widget-properties.md)。
   + `QueryStatement` – 儀表板重新整理時CloudTrail 執行的查詢。只要事件資料存放區存在於您的帳戶中，您就可以跨多個事件資料存放區進行查詢。
   + `QueryParameters` – 自訂儀表板支援下列`QueryParameters`值：`$StartTime$`、 `$Period$`和 `$EndTime$`。若要使用 ，請在`QueryStatement`您要取代 參數的 `?`中`QueryParameters`放置 。執行查詢時，CloudTrail 會填入參數。

   下列範例會建立具有四個小工具的儀表板，每個檢視類型之一。
**注意**  
在此範例中， `?` 被單引號包圍，因為它與 搭配使用`eventTime`。根據您執行的作業系統，您可能需要使用逸出引號括住單引號。如需詳細資訊，請參閱 [中的使用引號和常值搭配字串 AWS CLI](https://docs.aws.amazon.com/cli/v1/userguide/cli-usage-parameters-quoting-strings.html)。

   ```
   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$"]
       }
     ]'
   ```

1. 建立個別檔案，其中包含小工具 中每個事件資料存放區所需的資源政策`QueryStatement`。使用下列範例政策陳述式命名檔案 *policy.json*：

    將 *123456789012* 取代為您的帳戶 ID，*arn：aws：cloudtrail：us-east-1：123456789012：dashboard/exampleDashboard* 取代為儀表板的 ARN。

   如需儀表板資源型政策的詳細資訊，請參閱 [範例：允許 CloudTrail 執行查詢以重新整理儀表板](security_iam_resource-based-policy-examples.md#security_iam_resource-based-policy-examples-eds-dashboard)。

1. 執行 `put-resource-policy`命令來連接政策。您也可以在 CloudTrail 主控台上更新事件資料存放區的資源型政策。

   下列範例會將資源型政策連接至事件資料存放區。

   ```
   aws cloudtrail put-resource-policy \
   --resource-arn eds-arn \
   --resource-policy file://policy.json
   ```

1. 執行 `put-resource-policy`命令，將資源型政策連接至儀表板。如需政策範例，請參閱 [儀表板的資源型政策範例](security_iam_resource-based-policy-examples.md#security_iam_resource-based-policy-examples-dashboards)。

   下列範例會將資源型政策連接至儀表板。將 *account-id* 取代為您的帳戶 ID，將 *dashboard-arn* 取代為儀表板的 ARN。

   ```
   aws cloudtrail put-resource-policy \
   --resource-arn dashboard-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"}}}]}'
   ```

1. 執行 `update-dashboard`命令，透過設定 `--refresh-schedule` 參數來設定和啟用重新整理排程。

   `--refresh-schedule` 包含下列選用參數：
   + `Frequency` – 排程`Value`的 `Unit`和 。

     對於自訂儀表板，單位可以是 `HOURS`或 `DAYS`。

      對於自訂儀表板，當單位為 `1`、、`6`、 時`12`，以下值有效`HOURS`： `24`

     對於自訂儀表板，單位`DAYS`為 時的唯一有效值。 `1`
   + `Status` – 指定是否啟用重新整理排程。將值設定為 `ENABLED` 以啟用重新整理排程，或設定為 `DISABLED` 以關閉重新整理排程。
   + `TimeOfDay ` – 在 UTC 中執行排程的時間；每小時僅參考分鐘；預設值為 00：00。

   下列範例會設定每六小時的重新整理排程，並啟用排程。

   ```
   aws cloudtrail update-dashboard --dashboard-id AccountActivityDashboard \
   --refresh-schedule '{"Frequency": {"Unit": "HOURS", "Value": 6}, "Status": "ENABLED"}'
   ```

## 使用 啟用反白儀表板 AWS CLI
<a name="lake-dashboard-cli-create-highlights"></a>

下列程序說明如何建立反白儀表板、將所需的資源型政策連接至事件資料存放區和儀表板，以及更新儀表板以設定和啟用重新整理排程。

1. 執行 `create-dashboard`命令來建立反白儀表板。若要建立此儀表板， `--name` 必須是 `AWSCloudTrail-Highlights`。

   ```
   aws cloudtrail create-dashboard --name AWSCloudTrail-Highlights
   ```

1. 針對您帳戶中的每個事件資料存放區，執行 `put-resource-policy`命令，將資源型政策連接至事件資料存放區。您也可以在 CloudTrail 主控台上更新事件資料存放區的資源型政策。如需政策範例，請參閱 [範例：允許 CloudTrail 執行查詢以重新整理儀表板](security_iam_resource-based-policy-examples.md#security_iam_resource-based-policy-examples-eds-dashboard)。

   下列範例會將資源型政策連接至事件資料存放區。將 *account-id* 取代為您的帳戶 ID、將 *eds-arn* 取代為事件資料存放區的 ARN，並將 *dashboard-arn* 取代為儀表板的 ARN。

   ```
   aws cloudtrail put-resource-policy \
   --resource-arn eds-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"}}} ]}'
   ```

1. 執行 `put-resource-policy`命令，將資源型政策連接至儀表板。如需政策範例，請參閱 [儀表板的資源型政策範例](security_iam_resource-based-policy-examples.md#security_iam_resource-based-policy-examples-dashboards)。

   下列範例會將資源型政策連接至儀表板。將 *account-id* 取代為您的帳戶 ID，將 *dashboard-arn* 取代為儀表板的 ARN。

   ```
   aws cloudtrail put-resource-policy \
   --resource-arn dashboard-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"}}}]}'
   ```

1. 執行 `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"}'
   ```