

# 使用 AWS CloudTrail 記錄 Amazon IVS API 呼叫
<a name="cloudtrail"></a>

Amazon Interactive Video Service (IVS) 整合了 AWS CloudTrail，後者是一項服務，可提供由使用者、角色或 AWS 服務在 Amazon IVS 中所採取之動作的記錄。CloudTrail 會將 Amazon IVS 的所有 API 呼叫擷取為事件。擷取的呼叫包括來自 Amazon IVS 主控台和應用程式的 API 呼叫。

如果您建立*追蹤*，就可以將 CloudTrail 事件持續交付到 Amazon S3 儲存貯體，包括 Amazon IVS 事件。即使您未設定追蹤，依然可以透過 CloudTrail 主控台中的 **Event history** (事件歷史記錄) 檢視最新事件。您可以利用 CloudTrail 所收集的資訊來判斷向 Amazon IVS 發出的請求，以及發出請求的 IP 地址、人員、時間和其他詳細資訊。

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

## CloudTrail 中的 Amazon IVS 資訊
<a name="cloudtrail-ivs-info"></a>

當您建立帳戶時，系統即會在 AWS 帳戶中啟用 CloudTrail。此外，Amazon IVS 發生活動時，系統便會將該活動記錄至 CloudTrail 事件，並將其他 AWS 服務事件記錄到 **Event history** (事件歷史記錄) 中。您可以檢視、搜尋和下載 AWS 帳戶中的最新事件。如需詳細資訊，請參閱使用 [CloudTrail 事件歷史記錄檢視事件](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/view-cloudtrail-events.html)。

若要持續記錄您 AWS 帳戶中正在進行的事件 (包括 Amazon IVS 的事件)，請建立追蹤。追蹤可讓 CloudTrail 將日誌檔案交付到 Amazon S3 儲存貯體。依預設，當您在 CloudTrail 主控台建立追蹤時，該追蹤會套用到所有 AWS 區域。追蹤會記錄來自 AWS 分割區中所有區域的事件，然後將所有日誌檔案交付到您指定的 Amazon S3 儲存貯體。除此之外，您還可設定其他 AWS 服務，以分析和處理 CloudTrail 日誌收集到的事件資料。如需詳細資訊，請參閱 *CloudTrail 使用者指南*中的這些項目：
+ [建立 AWS 帳戶的追蹤](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)

所有 Amazon IVS 動作均由 CloudTrail 記錄，並將其記錄在[IVS 低延遲串流 API 參考](https://docs.aws.amazon.com/ivs/latest/LowLatencyAPIReference/Welcome.html)、[IVS 即時串流 API 參考](https://docs.aws.amazon.com/ivs/latest/RealTimeAPIReference/Welcome.html)，以及[IVS 聊天 API 參考](https://docs.aws.amazon.com/ivs/latest/ChatAPIReference/Welcome.html)中。例如，對 `CreateChannel`、`ListChannels` 和 `DeleteChannel` 操作的呼叫都會在 CloudTrail 日誌檔案中產生項目。

每一筆事件或日誌專案都會包含產生請求者的資訊。身分資訊可協助您判斷提出請求的身分是：
+ 擁有根或 AWS Identity and Access Management (IAM) 使用者登入資料
+ 使用某個角色的暫時安全登入資料或聯合身分使用者。
+ 透過其他 AWS 服務。

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

## 了解 Amazon IVS 日誌檔案項目
<a name="cloudtrail-log-entries"></a>

追蹤是一種組態，能讓事件以日誌檔案的形式交付到您指定的 Amazon S3 儲存貯體。一個事件為任何來源提出的單一請求，並包含請求動作、請求的日期和時間、請求參數等資訊。

CloudTrail 日誌檔案包含一個或多個日誌項目。CloudTrail 日誌檔案並非依公有 API 呼叫追蹤記錄的堆疊排序，因此不會以任何特定順序出現。

以下範例顯示 `CreateChannel` 操作的 CloudTrail 日誌項目。

```
{
    "eventVersion": "1.05",
    "userIdentity": {
        "type": "AssumedRole",
        "principalId": "ABCDEFGHIJK1L2EXAMPLE:account_name",
        "arn": "arn:aws:sts::123456789012:assumed-role/First_Streamer/1234567890123456789",
        "accountId": "123456789012",
        "accessKeyId": "ABCDEFGHIJKL1EXAMPLE",
        "sessionContext": {
            "sessionIssuer": {
                "type": "Role",
                "principalId": "ABCDEFGHIJK1L2EXAMPLE",
                "arn": "arn:aws:iam::123456789012:role/Admin",
                "accountId": "123456789012",
                "userName": "First_Streamer"
            },
            "webIdFederationData": {},
            "attributes": {
                "mfaAuthenticated": "false",
                "creationDate": "2020-04-02T20:57:43Z"
            }
        }
    },
    "eventTime": "2020-04-02T20:57:46Z",
    "eventSource": "ivs.amazonaws.com",
    "eventName": "CreateChannel",
    "awsRegion": "us-west-2",
    "sourceIPAddress": "10.10.10.10",
    "userAgent": "console.amazonaws.com",
    "requestParameters": {
        "name": "default"
    },
    "responseElements": {
        "channel": {
            "arn": "arn:aws:ivs:us-west-2:123456789012:channel/1EXAMPLE",
            "authorized": false,
            "ingestEndpoint": "EXAMPLE.global-contribute.live-video.net",
            "latencyMode": "LOW",
            "name": "default",
            "playbackUrl": "https://EXAMPLE.m3u8",
            "tags": {}
        },
        "streamKey": {
            "arn": "arn:aws:ivs:us-west-2:123456789012:stream-key/2EXAMPLE",
            "channelArn": "arn:aws:ivs:us-west-2:123456789012:channel/1EXAMPLE",
            "tags": {}
        }
    },
    "requestID": "12a34bc5-EXAMPLE",
    "eventID": "a1b2c3de-EXAMPLE",
    "readOnly": false,
    "eventType": "AwsApiCall",
    "recipientAccountId": "123456789012"
}
```