

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

# 使用 檢視線索的 Insights 事件 AWS CLI
<a name="view-insights-events-cli"></a>

本節說明如何使用 AWS CLI `lookup-events`和 `list-insights-data`命令來查詢過去 90 天的 Insights 事件，以取得已啟用 Insights 事件的線索。如需有關如何在線索上啟用 CloudTrail Insights 的資訊，請參閱 [使用 記錄線索的 Insights 事件 AWS CLI](insights-events-CLI-enable.md#insights-events-CLI-enable-trails)。

**注意**  
您無法使用 `lookup-events`或 `list-insights-data`命令來查詢事件資料存放區的 Insights 事件，不過，CloudTrail Lake 為 Insights 事件資料存放區提供許多範例查詢。如需詳細資訊，請參閱[檢視 Insights 事件的範例查詢](insights-events-view-lake.md#insights-events-lake-queries)。

此 `lookup-events` 命令提供以下選項：
+ `--end-time`
+ `--event-category`
+ `--max-results`
+ `--start-time`
+ `--lookup-attributes`
+ `--next-token`
+ `--generate-cli-skeleton`
+ `--cli-input-json`

此 `list-insights-data` 命令提供以下選項：
+ `--end-time`
+ `--data-type`
+ `--max-results`
+ `--start-time`
+ `--dimensions`
+ `--next-token`
+ `--generate-cli-skeleton`
+ `--cli-input-json`

如需使用 的一般資訊 AWS Command Line Interface，請參閱[AWS Command Line Interface 《 使用者指南》](https://docs.aws.amazon.com/cli/latest/userguide/)。

**Contents**
+ [先決條件](#aws-cli-prerequisites-for-insights)
+ [取得命令列說明](#getting-command-line-help-insights)
+ [查詢管理事件的 Insights 事件](#looking-up-management-insights-with-the-aws-cli)
+ [查詢 Insights 事件以取得資料事件](#looking-up-data-insights-with-the-aws-cli)
+ [指定要傳回的管理事件 Insights 事件數量](#specify-the-number-of-management-insights-to-return)
+ [指定要傳回的資料事件 Insights 事件數目](#specify-the-number-of-data-insights-to-return)
+ [依時間範圍查詢管理事件的 Insights 事件](#look-up-management-insights-by-time-range)
+ [依時間範圍查詢資料事件的 Insights 事件](#look-up-data-insights-by-time-range)
+ [依屬性查詢管理事件的 Insights 事件](#look-up-management-insights-by-attributes)
  + [屬性查詢範例](#attribute-lookup-example-insights)
+ [依維度查詢資料事件的 Insights 事件](#look-up-data-insights-by-attributes)
  + [維度查詢範例](#dimension-lookup-example-insights)
+ [為管理事件指定 Insights 事件結果的下一頁](#specify-next-page-of-management-results)
+ [為管理事件指定 Insights 事件結果的下一頁](#specify-next-page-of-data-results)
+ [從管理事件的 Insights 事件檔案中取得 JSON 輸入](#json-input-from-file-managemenet-insights)
+ [從資料事件的 Insights 事件檔案中取得 JSON 輸入](#json-input-from-file-data-insights)
+ [查詢輸出欄位](#view-insights-events-cli-output-fields)

## 先決條件
<a name="aws-cli-prerequisites-for-insights"></a>
+ 若要執行 AWS CLI 命令，您必須安裝 AWS CLI。如需詳細資訊，請參閱 [Get started with the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html)。
+ 請確定您的 AWS CLI 版本大於 1.6.6。若要驗證 CLI 版本，請在命令列上執行 **aws --version**。
+ 若要設定 AWS CLI 工作階段的帳戶、區域和預設輸出格式，請使用 **aws configure**命令。如需詳細資訊，請參閱[設定 AWS 命令列界面](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html)。
+  若要在 API 呼叫率上記錄 Insights 事件，追蹤必須記錄`write`管理事件。若要在 API 錯誤率上記錄 Insights 事件，追蹤必須記錄`read`或`write`管理事件。

**注意**  
CloudTrail AWS CLI 命令區分大小寫。

## 取得命令列說明
<a name="getting-command-line-help-insights"></a>

若要查看 `lookup-events` 的命令列說明，請輸入下列命令：

```
aws cloudtrail lookup-events help
```

## 查詢管理事件的 Insights 事件
<a name="looking-up-management-insights-with-the-aws-cli"></a>

若要查看 50 個最新的 Insights 事件，請輸入下列命令。

```
aws cloudtrail lookup-events --event-category insight
```

傳回的事件看起來類似下列範例：

```
{
    "NextToken": "kbOt5LlZe++mErCebpy2TgaMgmDvF1kYGFcH64JSjIbZFjsuvrSqg66b5YGssKutDYIyII4lrP4IDbeQdiObkp9YAlju3oXd12juEXAMPLE=", 
    "Events": [
        {
            "eventVersion": "1.09",
            "eventTime": "2024-12-11T16:52:00Z",
            "awsRegion": "us-east-1",
            "eventID": "18378b1e-3653-433d-ba1e-aa11a5958f0c",
            "eventType": "AwsCloudTrailInsight",
            "recipientAccountId": "888888888888",
            "sharedEventID": "fccb064f-dd07-4822-97c0-11115d8b91d4",
            "insightDetails": {
                "state": "Start",
                "eventSource": "cloudtrail.amazonaws.com",
                "eventName": "DescribeQuery",
                "insightType": "ApiErrorRateInsight",
                "errorCode": "QueryIdNotFoundException",
                "sourceEventCategory": "Management",
                "insightContext": {
                    "statistics": {
                        "baseline": {
                            "average": 0
                        },
                        "insight": {
                            "average": 1.2
                        },
                        "insightDuration": 5,
                        "baselineDuration": 11092
                    },
                    "attributions": [
                        {
                            "attribute": "userIdentityArn",
                            "insight": [
                                {
                                    "value": "arn:aws:sts::888888888888:assumed-role/Admin",
                                    "average": 1.2
                                }
                            ],
                            "baseline": []
                        },
                        {
                            "attribute": "userAgent",
                            "insight": [
                                {
                                    "value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
                                    "average": 1.2
                                }
                            ],
                            "baseline": []
                        }
                    ]
                }
            },
            "eventCategory": "Insight"
        },
        {
            "eventVersion": "1.09",
            "eventTime": "2024-12-11T16:53:00Z",
            "awsRegion": "us-east-1",
            "eventID": "b32f10a0-f039-419a-bad7-e95468930a4f",
            "eventType": "AwsCloudTrailInsight",
            "recipientAccountId": "888888888888",
            "sharedEventID": "fccb064f-dd07-4822-97c0-11115d8b91d4",
            "insightDetails": {
                "state": "End",
                "eventSource": "cloudtrail.amazonaws.com",
                "eventName": "DescribeQuery",
                "insightType": "ApiErrorRateInsight",
                "errorCode": "QueryIdNotFoundException",
                "sourceEventCategory": "Management",
                "insightContext": {
                    "statistics": {
                        "baseline": {
                            "average": 0
                        },
                        "insight": {
                            "average": 6
                        },
                        "insightDuration": 1,
                        "baselineDuration": 11092
                    },
                    "attributions": [
                        {
                            "attribute": "userIdentityArn",
                            "insight": [
                                {
                                    "value": "arn:aws:sts::888888888888:assumed-role/Admin",
                                    "average": 6
                                }
                            ],
                            "baseline": []
                        },
                        {
                            "attribute": "userAgent",
                            "insight": [
                                {
                                    "value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
                                    "average": 6
                                }
                            ],
                            "baseline": []
                        }
                    ]
                }
            },
            "eventCategory": "Insight"
        }
    ]
}
```

如需輸出中查詢相關欄位的說明，請參閱本主題中的[查詢輸出欄位](#view-insights-events-cli-output-fields)。如需 Insights 事件中欄位的說明，請參閱 [追蹤的 Insights 事件 CloudTrail 記錄內容](cloudtrail-insights-fields-trails.md)。

## 查詢 Insights 事件以取得資料事件
<a name="looking-up-data-insights-with-the-aws-cli"></a>

若要查看 50 個最新的 Insights 事件，請輸入下列命令。

```
aws cloudtrail list-insights-data --data-type InsightsEvents --insight-source arn:aws:cloudtrail:us-east-2:123456789012:trail/{{TrailName}}
```

傳回的事件看起來類似下列範例：

```
    {  
    "NextToken": "kbOt5LlZe++mErCebpy2TgaMgmDvF1kYGFcH64JSjIbZFjsuvrSqg66b5YGssKutDYIyII4lrP4IDbeQdiObkp9YAlju3oXd12juEXAMPLE=",   
    "Events": [  
        {  
            "eventVersion": "1.09",  
            "eventTime": "2024-12-11T16:52:00Z",  
            "awsRegion": "us-east-2",  
            "eventID": "18378b1e-3653-433d-ba1e-aa11a5958f0c",  
            "eventType": "AwsCloudTrailInsight",  
            "recipientAccountId": "123456789012",  
            "sharedEventID": "fccb064f-dd07-4822-97c0-11115d8b91d4",  
            "insightDetails": {  
                "state": "Start",  
                "eventSource": "s3.amazonaws.com",  
                "eventName": "PutObject",  
                "insightType": "ApiErrorRateInsight",  
                "errorCode": "InvalidRequest",
                "sourceEventCategory": "Data",
                "insightContext": {  
                    "statistics": {  
                        "baseline": {  
                            "average": 0  
                        },  
                        "insight": {  
                            "average": 1.2  
                        },  
                        "insightDuration": 5,  
                        "baselineDuration": 11092  
                    },  
                    "attributions": [  
                        {  
                            "attribute": "userIdentityArn",  
                            "insight": [  
                                {  
                                    "value": "arn:aws:sts::123456789012:assumed-role/Admin",  
                                    "average": 1.2  
                                }  
                            ],  
                            "baseline": []  
                        },  
                        {  
                            "attribute": "userAgent",  
                            "insight": [  
                                {  
                                    "value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",  
                                    "average": 1.2  
                                }  
                            ],  
                            "baseline": []  
                        }  
                    ]  
                },  

                "insightSource": "arn:aws:cloudtrail:us-east-2:123456789012:trail/{{TrailName}}"  
            },  
            "eventCategory": "Insight"  
        },  
        {  
            "eventVersion": "1.09",  
            "eventTime": "2024-12-11T16:53:00Z",  
            "awsRegion": "us-east-1",  
            "eventID": "b32f10a0-f039-419a-bad7-e95468930a4f",  
            "eventType": "AwsCloudTrailInsight",  
            "recipientAccountId": "123456789012",  
            "sharedEventID": "fccb064f-dd07-4822-97c0-11115d8b91d4",  
            "insightDetails": {  
                "state": "End",  
                "eventSource": "s3.amazonaws.com",  
                "eventName": "PutObject",  
                "insightType": "ApiErrorRateInsight",  
                "errorCode": "InvalidRequest",  
                "sourceEventCategory": "Data",  
                "insightContext": {  
                    "statistics": {  
                        "baseline": {  
                            "average": 0  
                        },  
                        "insight": {  
                            "average": 6  
                        },  
                        "insightDuration": 1,  
                        "baselineDuration": 11092  
                    },  
                    "attributions": [  
                        {  
                            "attribute": "userIdentityArn",  
                            "insight": [  
                                {  
                                    "value": "arn:aws:sts::123456789012:assumed-role/Admin",  
                                    "average": 6  
                                }  
                            ],  
                            "baseline": []  
                        },  
                        {  
                            "attribute": "userAgent",  
                            "insight": [  
                                {  
                                    "value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",  
                                    "average": 6  
                                }  
                            ],  
                            "baseline": []  
                        }  
                    ]  
                }, 

                "insightSource": "arn:aws:cloudtrail:us-east-2:123456789012:trail/{{TrailName}}"    
            },  
            "eventCategory": "Insight"  
        }  
    ]  
}
```

## 指定要傳回的管理事件 Insights 事件數量
<a name="specify-the-number-of-management-insights-to-return"></a>

若要為要傳回的管理事件指定 Insights 事件數量，請輸入下列命令。

```
aws cloudtrail lookup-events --event-category insight --max-results {{<integer>}}
```

若未指定 {{<integer>}} 的預設值為 50。可能值為 1 到 50。下列範例會傳回一個結果。

```
aws cloudtrail lookup-events --event-category insight --max-results 1
```

## 指定要傳回的資料事件 Insights 事件數目
<a name="specify-the-number-of-data-insights-to-return"></a>

若要為要傳回的資料事件指定 Insights 事件數量，請輸入下列命令。

```
aws cloudtrail list-insights-data --data-type InsightsEvents --insight-source arn:aws:cloudtrail:us-east-2:123456789012:trail/{{TrailName}} --max-results {{<integer>}}
```

若未指定 {{<integer>}} 的預設值為 50。可能值為 1 到 50。下列範例會傳回一個結果。

```
aws cloudtrail list-insights-data --data-type InsightsEvents --insight-source arn:aws:cloudtrail:us-east-2:123456789012:trail/{{TrailName}} --max-results 1
```

## 依時間範圍查詢管理事件的 Insights 事件
<a name="look-up-management-insights-by-time-range"></a>

過去 90 天的管理事件洞見事件可供查詢。若要指定時間範圍，請輸入下列命令。

```
aws cloudtrail lookup-events --event-category insight --start-time {{<timestamp>}} --end-time {{<timestamp>}}
```

`--start-time {{<timestamp>}}` 指定 (UTC) 只會傳回在所指定時間或之後發生的 Insights 事件。如果指定的開始時間晚於指定的結束時間，則會傳回錯誤。

`--end-time {{<timestamp>}}` 指定 (UTC) 只會傳回在所指定時間或之前發生的 Insights 事件。如果指定的結束時間早於指定的開始時間，則會傳回錯誤。

預設的開始時間是過去 90 天內可使用資料的最早日期。預設的結束時間是在最接近目前時間所發生之事件的時間。

所有時間戳記均會以 UTC 顯示。

## 依時間範圍查詢資料事件的 Insights 事件
<a name="look-up-data-insights-by-time-range"></a>

過去 90 天的資料事件洞見事件可供查詢。若要指定時間範圍，請輸入下列命令。

```
aws cloudtrail list-insights-data --data-type InsightsEvents --insight-source arn:aws:cloudtrail:us-east-2:123456789012:trail/{{TrailName}} --start-time {{<timestamp>}} --end-time {{<timestamp>}}
```

`--start-time {{<timestamp>}}` 指定 (UTC) 只會傳回在所指定時間或之後發生的 Insights 事件。如果指定的開始時間晚於指定的結束時間，則會傳回錯誤。

`--end-time {{<timestamp>}}` 指定 (UTC) 只會傳回在所指定時間或之前發生的 Insights 事件。如果指定的結束時間早於指定的開始時間，則會傳回錯誤。

預設的開始時間是過去 90 天內可使用資料的最早日期。預設的結束時間是在最接近目前時間所發生之事件的時間。

所有時間戳記均會以 UTC 顯示。

## 依屬性查詢管理事件的 Insights 事件
<a name="look-up-management-insights-by-attributes"></a>

若要依屬性進行篩選，請輸入下列命令。

```
aws cloudtrail lookup-events --event-category insight --lookup-attributes AttributeKey={{<attribute>}},AttributeValue={{<string>}}
```

您只能為每個 **lookup-events** 命令指定一個屬性鍵/值對。以下是 `AttributeKey` 的有效 Insights 事件值。值名稱區分大小寫。
+ `EventId`
+ `EventName`
+ `EventSource`

的長度上限為 `AttributeValue` 2000 個字元。下列字元 ('`_`'、'` `'、'`,`'、'`\\n`') 計算為 2000 個字元限制的兩個字元。

### 屬性查詢範例
<a name="attribute-lookup-example-insights"></a>

下列範例命令會傳回 `EventName` 值為 `PutRule` 的 Insights 事件。

```
aws cloudtrail lookup-events --event-category insight --lookup-attributes AttributeKey=EventName, AttributeValue=PutRule
```

下列範例命令會傳回 `EventId` 值為 `b5cc8c40-12ba-4d08-a8d9-2bceb9a3e002` 的 Insights 事件。

```
aws cloudtrail lookup-events --event-category insight --lookup-attributes AttributeKey=EventId, AttributeValue=b5cc8c40-12ba-4d08-a8d9-2bceb9a3e002
```

下列範例命令會傳回 `EventSource` 值為 `iam.amazonaws.com` 的 Insights 事件。

```
aws cloudtrail lookup-events --event-category insight --lookup-attributes AttributeKey=EventSource, AttributeValue=iam.amazonaws.com
```

## 依維度查詢資料事件的 Insights 事件
<a name="look-up-data-insights-by-attributes"></a>

若要依維度篩選，請輸入下列命令。

```
aws cloudtrail list-insights-data --data-type InsightsEvents --insight-source arn:aws:cloudtrail:us-east-2:123456789012:trail/{{TrailName}} 
        --dimensions {{<DimensionKey>}}={{<DimensionValue>}}
```

每個**list-insights-events**命令只能指定一個維度鍵/值對。以下是 `DimensionKey` 的有效 Insights 事件值。值名稱區分大小寫。
+ `EventId`
+ `EventName`
+ `EventSource`

的長度上限為 `DimensionValue` 2000 個字元。下列字元 ('`_`'、'` `'、'`,`'、'`\\n`') 計算為 2000 個字元限制的兩個字元。

### 維度查詢範例
<a name="dimension-lookup-example-insights"></a>

下列範例命令會傳回 `EventName` 值為 `PutObject` 的 Insights 事件。

```
aws cloudtrail list-insights-data --data-type InsightsEvents --insight-source arn:aws:cloudtrail:us-east-2:123456789012:trail/{{TrailName}} --dimensions EventName=PutObject
```

下列範例命令會傳回 `EventId` 值為 `b5cc8c40-12ba-4d08-a8d9-2bceb9a3e002` 的 Insights 事件。

```
aws cloudtrail list-insights-data --data-type InsightsEvents --insight-source arn:aws:cloudtrail:us-east-2:123456789012:trail/{{TrailName}} --dimensions EventId=b5cc8c40-12ba-4d08-a8d9-2bceb9a3e002
```

下列範例命令會傳回 `EventSource` 值為 `s3.amazonaws.com` 的 Insights 事件。

```
aws cloudtrail list-insights-data --data-type InsightsEvents --insight-source arn:aws:cloudtrail:us-east-2:123456789012:trail/{{TrailName}} --dimensions EventSource=s3.amazonaws.com
```

## 為管理事件指定 Insights 事件結果的下一頁
<a name="specify-next-page-of-management-results"></a>

若要從 `lookup-events` 命令取得下一頁的結果，請輸入下列命令。

```
aws cloudtrail lookup-events --event-category insight {{<same parameters as previous command>}} --next-token={{<token>}}
```

在此命令中，{{<token>}} 的值取自先前命令輸出的第一個欄位。

當您在命令中使用 `--next-token` 時，必須使用與先前命令相同的參數。例如，假設您執行下列命令。

```
aws cloudtrail lookup-events --event-category insight --lookup-attributes AttributeKey=EventName, AttributeValue=PutRule
```

若要取得下一頁的結果，您的下一個命令會如下所示。

```
aws cloudtrail lookup-events --event-category insight --lookup-attributes AttributeKey=EventName,AttributeValue=PutRule --next-token=EXAMPLEZe++mErCebpy2TgaMgmDvF1kYGFcH64JSjIbZFjsuvrSqg66b5YGssKutDYIyII4lrP4IDbeQdiObkp9YAlju3oXd12juEXAMPLE=
```

## 為管理事件指定 Insights 事件結果的下一頁
<a name="specify-next-page-of-data-results"></a>

若要從 `list-insights-data` 命令取得下一頁的結果，請輸入下列命令。

```
aws cloudtrail list-insights-data --data-type InsightsEvents --insight-source arn:aws:cloudtrail:us-east-2:123456789012:trail/{{TrailName}}{{<same parameters as previous command>}} --next-token={{<token>}}
```

在此命令中，{{<token>}} 的值取自先前命令輸出的第一個欄位。

當您在命令中使用 `--next-token` 時，必須使用與先前命令相同的參數。例如，假設您執行下列命令。

```
aws cloudtrail list-insights-data --data-type InsightsEvents --insight-source arn:aws:cloudtrail:us-east-2:123456789012:trail/{{TrailName}} --dimensions EventName=PutObject
```

若要取得下一頁的結果，您的下一個命令會如下所示。

```
aws cloudtrail list-insights-data --data-type InsightsEvents --insight-source arn:aws:cloudtrail:us-east-2:123456789012:trail/{{TrailName}} --dimensions EventName=PutObject --next-token=EXAMPLEZe++mErCebpy2TgaMgmDvF1kYGFcH64JSjIbZFjsuvrSqg66b5YGssKutDYIyII4lrP4IDbeQdiObkp9YAlju3oXd12juEXAMPLE=
```

## 從管理事件的 Insights 事件檔案中取得 JSON 輸入
<a name="json-input-from-file-managemenet-insights"></a>

 AWS CLI 某些 AWS 服務的 有兩個參數 `--generate-cli-skeleton`和 `--cli-input-json`，可用來產生 JSON 範本，您可以修改並用作`--cli-input-json`參數的輸入。本節說明如何搭配使用這些參數與 `aws cloudtrail lookup-events`。如需詳細資訊，請參閱[AWS CLI 骨架和輸入檔案](https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-skeleton.html)。

**從檔案取得 JSON 輸入來查詢 Insights 事件**

1. 將 `lookup-events` 輸出重新導向至檔案，以建立與 `--generate-cli-skeleton` 搭配使用的輸入範本，如下列範例所示。

   ```
   aws cloudtrail lookup-events --event-category insight --generate-cli-skeleton > LookupEvents.txt
   ```

   所產生的範本檔案 (在此情況下為 LookupEvents.txt) 如下。

   ```
   {
       "LookupAttributes": [
           {
               "AttributeKey": "",
               "AttributeValue": ""
           }
       ],
       "StartTime": null,
       "EndTime": null,
       "MaxResults": 0,
       "NextToken": ""
   }
   ```

1. 視需要使用文字編輯器來修改 JSON。JSON 輸入只能包含所指定的值。
**重要**  
必須先從範本移除所有空白值或 null 值，才能使用它。

   下列範例指定時間範圍以及要傳回的結果數目上限。

   ```
   {
       "StartTime": "2023-11-01",
       "EndTime": "2023-12-12",
       "MaxResults": 10
   }
   ```

1. 若要使用編輯過的檔案做為輸入，請使用語法 `--cli-input-json file://`{{<filename>}}，如下列範例所示。

   ```
   aws cloudtrail lookup-events --event-category insight --cli-input-json file://LookupEvents.txt
   ```

**注意**  
您可以在與 `--cli-input-json` 相同的命令列上使用其他引數。

## 從資料事件的 Insights 事件檔案中取得 JSON 輸入
<a name="json-input-from-file-data-insights"></a>

 AWS CLI 某些 AWS 服務的 有兩個參數 `--generate-cli-skeleton`和 `--cli-input-json`，可用來產生 JSON 範本，您可以修改並用作`--cli-input-json`參數的輸入。本節說明如何搭配使用這些參數與 `aws cloudtrail list-insights-data`。如需詳細資訊，請參閱[AWS CLI 骨架和輸入檔案](https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-skeleton.html)。

**從檔案取得 JSON 輸入來查詢 Insights 事件**

1. 將 `list-insights-data` 輸出重新導向至檔案，以建立與 `--generate-cli-skeleton` 搭配使用的輸入範本，如下列範例所示。

   ```
   aws cloudtrail list-insights-data --data-type InsightsEvents --generate-cli-skeleton > ListInsightsData.txt
   ```

   產生的範本檔案 （在此案例中為 ListInsightsData.txt) 如下所示。

   ```
   {  
      "InsightSource": "",
       "DataType": "InsightsEvents", 
       "Dimensions":
       {
           "KeyName": ""
       },
       "StartTime": null,
       "EndTime": null,
       "MaxResults": 0,
       "NextToken": ""
   }
   ```

1. 視需要使用文字編輯器來修改 JSON。JSON 輸入只能包含所指定的值。
**重要**  
必須先從範本移除所有空白值或 null 值，才能使用它。

   下列範例指定時間範圍以及要傳回的結果數目上限。

   ```
   {
       
      "InsightSource": "arn:aws:cloudtrail:us-east-2:123456789012:trail/{{TrailName}}", 
       "DataType": "InsightsEvents", 
       "Dimensions":
       {
           "EventName": "PutObject"
       },
       "StartTime": "2025-11-01",
       "EndTime": "2025-11-05",
       "MaxResults": 1
   }
   ```

1. 若要使用編輯過的檔案做為輸入，請使用語法 `--cli-input-json file://`{{<filename>}}，如下列範例所示。

   ```
   aws cloudtrail list-insights-data --data-type InsightsEvents --cli-input-json file://ListInsightsData.txt
   ```

**注意**  
您可以在與 `--cli-input-json` 相同的命令列上使用其他引數。

## 查詢輸出欄位
<a name="view-insights-events-cli-output-fields"></a>

**事件**  
根據所指定查詢屬性和時間範圍的查詢事件清單。事件清單是依時間排序，而且會先列出最新的事件。每個項目都會包含查詢請求的資訊，以及包含以字串呈現所擷取的 CloudTrail 事件。  
下列項目說明每個查詢事件中的欄位。

**CloudTrailEvent**  
包含以物件呈現所傳回事件的 JSON 字串。如需所有傳回之元素的資訊，請參閱[記錄內文內容](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-event-reference-record-contents.html)。

**EventId**  
字串，包含所傳回事件的 GUID。

**EventName**  
字串，包含所傳回事件的名稱。

**EventSource**  
提出請求的 AWS 服務。

**EventTime**  
事件的日期和時間 (UNIX 時間格式)。

**資源**  
所傳回之事件所參考的資源清單。每個資源項目都會指定資源類型和資源名稱。

**ResourceName**  
字串，包含事件所參考資源的名稱。

**ResourceType**  
字串，包含事件所參考資源的類型。無法判定資源類型時，會傳回 null。

**使用者名稱**  
字串，包含所傳回事件之帳戶的使用者名稱。

**NextToken**  
字串，可從先前的 `lookup-events` 命令取得下一頁的結果。若要使用字符，參數必須與原始命令中的參數相同。如果 `NextToken` 項目未出現在輸出中，則沒有可傳回的其他結果。

如需 CloudTrail Insights 事件的詳細資訊，請參閱此指南中的 [使用 CloudTrail Insights](logging-insights-events-with-cloudtrail.md)。