

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

# 使用 記錄 AWS IoT SiteWise API 呼叫 AWS CloudTrail
<a name="logging-using-cloudtrail"></a>

AWS IoT SiteWise 已與 服務整合 AWS CloudTrail，此服務提供使用者、角色或 AWS 服務在其中採取之動作的記錄 AWS IoT SiteWise。CloudTrail 會擷取 AWS IoT SiteWise 的 API 呼叫當作事件。擷取的呼叫包括來自 AWS IoT SiteWise 主控台的呼叫，以及對 AWS IoT SiteWise API 操作的程式碼呼叫。如果您建立線索，則可以啟用 CloudTrail 事件持續交付至 Amazon S3 儲存貯體，包括 的事件 AWS IoT SiteWise。即使您未設定追蹤，依然可以透過 CloudTrail 主控台中的**事件歷史記錄**檢視最新事件。您可以使用 CloudTrail 所收集的資訊來判斷提出的請求 AWS IoT SiteWise、提出請求的 IP 地址、提出請求的人員、提出請求的時間，以及其他詳細資訊。

如需有關 CloudTrail 的相關資訊，請參閱 [AWS CloudTrail 使用者指南](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/)。

## AWS IoT SiteWise CloudTrail 中的資訊
<a name="sitewise-info-in-cloudtrail"></a>

當您建立 AWS 帳戶時，會在您的帳戶上啟用 CloudTrail。在 中發生支援的事件活動時 AWS IoT SiteWise，該活動會與**事件歷史記錄**中的其他服務 AWS 事件一起記錄在 CloudTrail 事件中。您可以在 AWS 帳戶中檢視、搜尋和下載最近的事件。如需詳細資訊，請參閱[使用 CloudTrail 事件歷史記錄檢視事件](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/view-cloudtrail-events.html)。

若要持續記錄您 AWS 帳戶中的事件，包括 的事件 AWS IoT SiteWise，請建立追蹤。*線索*能讓 CloudTrail 將日誌檔案交付至 Amazon S3 儲存貯體。根據預設，當您在主控台建立線索時，線索會套用到所有 AWS 區域。線索會記錄 AWS 分割區中所有區域的事件，並將日誌檔案傳送到您指定的 Amazon S3 儲存貯體。此外，您可以設定其他 AWS 服務，以進一步分析和處理 CloudTrail 日誌中所收集的事件資料。如需詳細資訊，請參閱下列內容：
+ [建立追蹤的概觀](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-create-and-update-a-trail.html)
+ [CloudTrail 支援的服務和整合](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-aws-service-specific-topics.html#cloudtrail-aws-service-specific-topics-integrations)
+  [設定 CloudTrail 的 Amazon SNS 通知](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/configure-sns-notifications-for-cloudtrail.html)
+ [接收多個區域的 CloudTrail 日誌檔案](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/receive-cloudtrail-log-files-from-multiple-regions.html)及[接收多個帳戶的 CloudTrail 日誌檔案](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-receive-logs-from-multiple-accounts.html)

每一筆事件或日誌專案都會包含產生請求者的資訊。身分資訊可協助您判斷下列事項：
+ 是否使用根或 AWS Identity and Access Management (IAM) 使用者登入資料提出請求。
+ 提出該請求時，是否使用了特定角色或聯合身分使用者的暫時安全憑證。
+ 請求是否由其他 AWS 服務提出。

如需詳細資訊，請參閱 [CloudTrail userIdentity 元素](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-event-reference-user-identity.html)。

## AWS IoT SiteWise CloudTrail 中的資料事件
<a name="service-name-data-events-cloudtrail"></a>

[資料事件](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/logging-data-events-with-cloudtrail.html#logging-data-events)提供在資源上或在資源中執行的資源操作的相關資訊 (例如，讀取或寫入 Amazon S3 物件)。這些也稱為資料平面操作。資料事件通常是大量資料的活動。根據預設，CloudTrail 不會記錄資料事件。CloudTrail **事件歷史記錄**不會記錄資料事件。

資料事件需支付額外的費用。如需 CloudTrail 定價的詳細資訊，請參閱 [AWS CloudTrail 定價](https://aws.amazon.com/cloudtrail/pricing/)。

您可以使用 CloudTrail 主控台 AWS CLI或 CloudTrail API 操作來記錄 AWS IoT SiteWise 資源類型的資料事件。本節中的[表格](#data-events-table)顯示可用的資源類型 AWS IoT SiteWise。
+ 若要使用 CloudTrail 主控台記錄資料事件，請建立[線索](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-create-a-trail-using-the-console-first-time.html#creating-a-trail-in-the-console)或[事件資料存放區](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/query-event-data-store-cloudtrail.html)以記錄資料事件，或[更新現有的線索或事件資料存放區](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/logging-data-events-with-cloudtrail.html#logging-data-events-console)以記錄資料事件。

  1. 選擇**資料事件**以記錄資料事件。

  1. 從**資料事件類型**清單中，選擇您要記錄資料事件的資源類型。

  1. 選擇您要使用的日誌選取器範本。您可以記錄資源類型的所有資料事件、記錄所有`readOnly`事件、記錄所有`writeOnly`事件，或建立自訂日誌選取器範本來篩選 `readOnly`、 `eventName`和 `resources.ARN` 欄位。
+ 若要使用 記錄資料事件 AWS CLI，請設定 `--advanced-event-selectors` 參數以將 `eventCategory` 欄位設定為等於 ，`Data`並將 `resources.type` 欄位設定為等於資源類型值 （請參閱 [資料表](#data-events-table))。您可以新增條件來篩選 `readOnly`、 `eventName`和 `resources.ARN` 欄位的值。
  + 若要設定線索來記錄資料事件，請執行 [AWS CloudTrail put-event-selectors](https://docs.aws.amazon.com/cli/latest/reference/cloudtrail/put-event-selectors.html) 命令。如需詳細資訊，請參閱[使用 記錄線索的資料事件 AWS CLI](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/logging-data-events-with-cloudtrail.html#logging-data-events-CLI-trail-examples)。
  + 若要設定事件資料存放區來記錄資料事件，請執行 [AWS CloudTrail create-event-data-store](https://docs.aws.amazon.com/cli/latest/reference/cloudtrail/create-event-data-store.html) 命令來建立新的事件資料存放區來記錄資料事件，或執行 [AWS CloudTrail update-event-data-store](https://docs.aws.amazon.com/cli/latest/reference/cloudtrail/update-event-data-store.html) 命令來更新現有的事件資料存放區。如需詳細資訊，請參閱[使用 記錄事件資料存放區的資料事件 AWS CLI](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/logging-data-events-with-cloudtrail.html#logging-data-events-CLI-eds-examples)。

下表列出 AWS IoT SiteWise 資源類型。**資料事件類型 (主控台)** 資料行會顯示從 CloudTrail 主控台上的**資料事件類型**清單中選擇的值。**resources.type 值**欄會顯示值，您會在使用 AWS CLI 或 CloudTrail APIs 設定進階事件選取器時指定此`resources.type`值。**記錄到 CloudTrail 的資料 API** 資料行會針對資源類型顯示記錄到 CloudTrail 的 API 呼叫。


| 資料事件類型 (主控台) | resources.type 值 | 記錄到 CloudTrail 的資料 APIs\* | 
| --- | --- | --- | 
| AWS IoT SiteWise 資產 |  AWS::IoTSiteWise::Asset  |  [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/iot-sitewise/latest/userguide/logging-using-cloudtrail.html)  | 
| AWS IoT SiteWise 時間序列 |  AWS::IoTSiteWise::TimeSeries  |  [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/iot-sitewise/latest/userguide/logging-using-cloudtrail.html)  | 
| AWS IoT SiteWise 助理 |  AWS::SitewiseAssistant::Conversation  |  [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/iot-sitewise/latest/userguide/logging-using-cloudtrail.html)  | 

**注意**  
 Cloudtrail 事件中記錄的 resources.type 取決於 API 請求中使用的識別符。如果在請求中指定資產 ID，則會記錄 Asset resources.type，否則會記錄 TimeSeries resources.type。

\*您可以設定進階事件選取器來篩選 `eventName`、 和 `resources.ARN` 欄位`readOnly`，以僅記錄對您重要的事件。如需有關這些欄位的詳細資訊，請參閱 [https://docs.aws.amazon.com/awscloudtrail/latest/APIReference/API_AdvancedFieldSelector.html](https://docs.aws.amazon.com/awscloudtrail/latest/APIReference/API_AdvancedFieldSelector.html)。

## AWS IoT SiteWise CloudTrail 中的 管理事件
<a name="service-name-management-events-cloudtrail"></a>

[記錄管理事件](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/logging-management-events-with-cloudtrail.html)提供有關對 AWS 帳戶中資源執行的管理操作的資訊。這些也稱為控制平面操作。根據預設，CloudTrail 記錄管理事件。

AWS IoT SiteWise 會將所有 AWS IoT SiteWise 控制平面操作記錄為管理事件。如需 AWS IoT SiteWise 記錄到 CloudTrail 的 AWS IoT SiteWise 控制平面操作清單，請參閱 [AWS IoT SiteWise API 參考](https://docs.aws.amazon.com/iot-sitewise/latest/APIReference/API_Operations.html)。

## 範例： AWS IoT SiteWise 日誌檔案項目
<a name="understanding-sitewise-entries"></a>

追蹤是一種組態，能讓事件以日誌檔案的形式交付到您指定的 Amazon S3 儲存貯體。CloudTrail 日誌檔案包含一或多個日誌專案。一個事件代表任何來源提出的單一請求，並包含所請求之操作的相關資訊、操作的日期和時間、請求參數等等。CloudTrail 日誌檔案並非依公有 API 呼叫的堆疊追蹤排序，因此不會以任何特定順序出現。

以下範例顯示的 CloudTrail 日誌項目會示範 `CreateAsset` 操作：

```
{
  "eventVersion": "1.05",
  "userIdentity": {
    "type": "IAMUser",
    "principalId": "AIDACKCEVSQ6C2EXAMPLE",
    "arn": "arn:aws:iam::123456789012:user/Administrator",
    "accountId": "123456789012",
    "accessKeyId": "AKIAIOSFODNN7EXAMPLE",
    "userName": "Administrator",
    "sessionContext": {
      "sessionIssuer": {},
      "webIdFederationData": {},
      "attributes": {
        "mfaAuthenticated": "false",
        "creationDate": "2020-03-11T17:26:40Z"
      }
    },
    "invokedBy": "signin.amazonaws.com"
  },
  "eventTime": "2020-03-11T18:01:22Z",
  "eventSource": "iotsitewise.amazonaws.com",
  "eventName": "CreateAsset",
  "awsRegion": "us-east-1",
  "sourceIPAddress": "203.0.113.0",
  "userAgent": "signin.amazonaws.com",
  "requestParameters": {
    "assetName": "Wind Turbine 1",
    "assetModelId": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE",
    "clientToken": "a1b2c3d4-5678-90ab-cdef-00000EXAMPLE"
  },
  "responseElements": {
    "assetId": "a1b2c3d4-5678-90ab-cdef-22222EXAMPLE",
    "assetArn": "arn:aws:iotsitewise:us-east-1:123456789012:asset/a1b2c3d4-5678-90ab-cdef-22222EXAMPLE",
    "assetStatus": {
      "state": "CREATING"
    }
  },
  "requestID": "a1b2c3d4-5678-90ab-cdef-aaaaaEXAMPLE",
  "eventID": "a1b2c3d4-5678-90ab-cdef-bbbbbEXAMPLE",
  "eventType": "AwsApiCall",
  "recipientAccountId": "123456789012"
}
```