

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

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

Detective 與 整合 AWS CloudTrail，該服務提供 Detective AWS 中使用者、角色或服務所採取動作的記錄。 會將 Detective 的所有API呼叫 CloudTrail 擷取為事件。擷取的呼叫包括從 Detective 主控台呼叫，以及對 Detective API操作的程式碼呼叫。
+ 如果您建立追蹤，則可以啟用 CloudTrail 事件連續交付至 Amazon S3 儲存貯體，包括 Detective 的事件。
+ 如果您未設定追蹤，仍然可以在 事件歷史記錄 中 CloudTrail檢視主控台中的最新事件。 ****

使用 收集的資訊 CloudTrail，您可以判斷下列事項：
+ 對 Detective 提出的請求
+ 提出請求的 IP 地址
+ 提出要求的人員
+ 所提出的時間
+ 有關請求的其他詳細資訊

若要進一步了解 CloudTrail，請參閱 [AWS CloudTrail 使用者指南 ](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/)。

## 中的偵測資訊 CloudTrail
<a name="detective-info-in-cloudtrail"></a>

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

如需 AWS 帳戶中事件的持續記錄，包括 Detective 的事件，請建立追蹤。*追蹤*可讓 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)
+ [設定 的 Amazon SNS Notifications CloudTrail](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)

CloudTrail 會記錄 Detective [API參考 中記錄的所有 Detective ](https://docs.aws.amazon.com/detective/latest/APIReference/)操作。

例如，呼叫 `CreateMembers`、 `AcceptInvitation`和 `DeleteMembers`操作會在 CloudTrail 日誌檔案中產生項目。

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

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

## 了解 Detective 日誌檔案項目
<a name="understanding-detective-entries"></a>

追蹤是一種組態，可讓您將事件作為日誌檔案交付至您指定的 Amazon S3 儲存貯體。 CloudTrail 日誌檔案包含一或多個日誌項目。

事件代表來自任何來源的單一請求。事件包含有關請求動作、動作日期和時間、請求參數等資訊。 CloudTrail log 檔案不是公開API呼叫的有序堆疊追蹤，因此項目不會以任何特定順序顯示。

下列範例顯示示範 `AcceptInvitation`動作的 CloudTrail 日誌項目。

```
      {
            "EventId": "f2545ee3-170f-4340-8af4-a983c669ce37",
            "Username": "JaneRoe",
            "EventTime": 1571956406.0,
            "CloudTrailEvent": "{\"eventVersion\":\"1.05\",\"userIdentity\":{\"type\":\"AssumedRole\",\"principalId\":\"AROAJZARKEP6WKJ5JHSUS:JaneRoe\",\"arn\":\"arn:aws:sts::111122223333:assumed-role/1A4R5SKSPGG9V/JaneRoe\",\"accountId\":\"111122223333\",\"accessKeyId\":\"AKIAIOSFODNN7EXAMPLE\",\"sessionContext\":{\"attributes\":{\"mfaAuthenticated\":\"false\",\"creationDate\":\"2019-10-24T21:54:56Z\"},\"sessionIssuer\":{\"type\":\"Role\",\"principalId\":\"AROAJZARKEP6WKJ5JHSUS\",\"arn\":\"arn:aws:iam::111122223333:role/1A4R5SKSPGG9V\",\"accountId\":\"111122223333\",\"userName\":\"JaneRoe\"}}},\"eventTime\":\"2019-10-24T22:33:26Z\",\"eventSource\":\"detective.amazonaws.com\",\"eventName\":\"AcceptInvitation\",\"awsRegion\":\"us-east-2\",\"sourceIPAddress\":\"192.0.2.123\",\"userAgent\":\"aws /3 aws-sdk-java/1.11.648 Linux/4.14.133-97.112.amzn2.x86_64 OpenJDK_64-Bit_Server_VM/25.201-b09 java/1.8.0_201 vendor/Oracle_Corporation exec-env/AWS_Lambda_java8\",\"errorCode\":\"ValidationException\",\"requestParameters\":{\"masterAccount\":\"111111111111\"},\"responseElements\":{\"message\":\"Invalid request body\"},\"requestID\":\"8437ff99-5ec4-4b1a-8353-173be984301f\",\"eventID\":\"f2545ee3-170f-4340-8af4-a983c669ce37\",\"readOnly\":false,\"eventType\":\"AwsApiCall\",\"recipientAccountId\":\"111122223333\"}",
            "EventName": "AcceptInvitation",
            "EventSource": "detective.amazonaws.com",
            "Resources": []
        },
```