

# IVS 聊天功能記錄
<a name="chat-logging"></a>

聊天記錄功能可讓您將聊天室中的所有訊息記錄到三個標準位置中的任何一個：Amazon S3 儲存貯體、Amazon CloudWatch Logs 或 Amazon Kinesis Data Firehose。接著，可使用日誌進行分析或建置聊天重播，該聊天重播會連接到即時影片工作階段。

## 啟用聊天室的聊天記錄
<a name="chat-logging-enable"></a>

聊天記錄是一種進階選項，可以透過將日誌組態與聊天室建立關聯來加以啟用。記錄組態是一種資源，可讓您指定聊天室訊息的記錄位置類型 (Amazon S3 儲存貯體、Amazon CloudWatch Logs 或 Amazon Kinesis Data Firehose)。如需有關建立和管理記錄組態的詳細資訊，請參閱 [Amazon IVS 聊天功能入門](getting-started-chat.md)和 [Amazon IVS 聊天功能 API Reference](https://docs.aws.amazon.com//ivs/latest/ChatAPIReference/Welcome.html) (《Amazon IVS 聊天功能 API 參考》)。

建立新聊天室 ([CreateRoom](https://docs.aws.amazon.com//ivs/latest/ChatAPIReference/API_CreateRoom.html)) 或更新現有聊天室 ([UpdateRoom](https://docs.aws.amazon.com//ivs/latest/ChatAPIReference/API_UpdateRoom.html)) 時，您最多可以將三個記錄組態與每個聊天室建立關聯。您可以將多個聊天室與相同的記錄組態建立關聯。

當至少一個作用中記錄組態與聊天室相關聯時，都會將透過 [Amazon IVS 聊天功能傳訊 API](https://docs.aws.amazon.com//ivs/latest/chatmsgapireference/welcome.html) 傳送到該聊天室的每個傳訊請求自動記錄到指定的位置。以下是傳播延遲的平均值 (從傳送傳訊請求到傳訊請求在指定位置可用時)：
+ Amazon S3 儲存貯體：5 分鐘
+ Amazon CloudWatch Logs 或 Amazon Kinesis Data Firehose：10 秒

## 訊息內容
<a name="chat-logging-message-content"></a>

### 格式
<a name="message-content-format"></a>

```
{
   "event_timestamp": "string",
   "type": "string",
   "version": "string",
   "payload": { "string": "string" }
}
```

### 欄位
<a name="message-content-fields"></a>


| 欄位 | 說明 | 
| --- | --- | 
| `event_timestamp` | Amazon IVS 聊天功能收到訊息的 UTC 時間戳記。 | 
| `payload` | 用戶端將從 Amazon IVS 聊天功能服務收到的 [Message (Subscribe)](https://docs.aws.amazon.com//ivs/latest/chatmsgapireference/actions-message-subscribe.html) 或 [Event (Subscribe)](https://docs.aws.amazon.com//ivs/latest/chatmsgapireference/actions-event-subscribe.html) JSON 承載。 | 
| `type` | 聊天訊息的類型。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/ChatUserGuide/chat-logging.html)  | 
| `version` | 訊息內容格式的版本。 | 

## Amazon S3 儲存貯體
<a name="chat-logging-s3-bucket"></a>

### 格式
<a name="s3-bucket-format"></a>

會以下列 S3 字首和檔案格式對訊息日誌進行組織和儲存：

```
AWSLogs/<account_id>/IVSChatLogs/<version>/<region>/room_<resource_id>/<year>/<month>/<day>/<hours>/<account_id>_IVSChatLogs_<version>_<region>_room_<resource_id>_<year><month><day><hours><minutes>_<hash>.log.gz
```

### 欄位
<a name="s3-bucket-fields"></a>


| 欄位 | 說明 | 
| --- | --- | 
| `<account_id>` | 從中建立聊天室的 AWS 帳戶 ID。 | 
| `<hash>` | 由系統產生的以確保唯一性的雜湊值。 | 
| `<region>` | 聊天室建立所在的 AWS 服務區域。 | 
| `<resource_id>` | 聊天室 ARN 的資源 ID 部分。 | 
| `<version>` | 訊息內容格式的版本。 | 
| `<year> / <month> / <day> / <hours> / <minute>` | Amazon IVS 聊天功能收到訊息的 UTC 時間戳記。 | 

### 範例
<a name="s3-bucket-example"></a>

```
AWSLogs/123456789012/IVSChatLogs/1.0/us-west-2/room_abc123DEF456/2022/10/14/17/123456789012_IVSChatLogs_1.0_us-west-2_room_abc123DEF456_20221014T1740Z_1766dcbc.log.gz
```

## Amazon CloudWatch Logs
<a name="chat-logging-cloudwatch-logs"></a>

### 格式
<a name="cloudwatch-logs-format"></a>

會以下列日誌串流名稱格式對訊息日誌進行組織及儲存：

```
aws/IVSChatLogs/<version>/room_<resource_id>
```

### 欄位
<a name="cloudwatch-logs-fields"></a>


| 欄位 | 說明 | 
| --- | --- | 
| `<resource_id>` | 聊天室 ARN 的資源 ID 部分。 | 
| `<version>` | 訊息內容格式的版本。 | 

### 範例
<a name="cloudwatch-logs-example"></a>

```
aws/IVSChatLogs/1.0/room_abc123DEF456
```

## Amazon Kinesis Data Firehose
<a name="chat-logging-kinesis-firehose"></a>

會以即時串流資料將訊息日誌傳送至交付串流，目的地包含 Amazon Redshift、Amazon OpenSearch Service、Splunk，以及任何自訂 HTTP 端點或受支援的第三方服務供應商所擁有的 HTTP 端點。如需詳細資訊，請參閱[什麼是 Amazon Kinesis Data Firehose](https://docs.aws.amazon.com/firehose/latest/dev/what-is-this-service.html?icmpid=docs_console_unmapped)。

## 限制
<a name="chat-logging-constraints"></a>
+ 您必須擁有訊息儲存所在的記錄位置。
+ 聊天室、記錄組態和記錄位置三者所在的 AWS 區域必須相同。
+ 聊天記錄只能使用作用中的記錄組態。
+ 您只能夠刪除不再與任何聊天室相關聯的記錄組態。

必須使用 AWS 憑證進行授權，才能將訊息記錄到您擁有的位置。為了向 IVS Chat 提供必要的存取權，建立記錄組態時會自動產生資源政策 (適用於 Amazon S3 儲存貯體或 CloudWatch 日誌) 或 AWS IAM [服務連結角色](https://docs.aws.amazon.com/IAM/latest/UserGuide/using-service-linked-roles.html) (SLR) (適用於 Amazon Kinesis Data Firehose)。*對角色或政策進行任何修改時請務必小心，因為這可能會影響聊天記錄的許可。*

## 使用 Amazon CloudWatch 監控錯誤
<a name="chat-logging-monitor-errors"></a>

您可以使用 Amazon CloudWatch 監控聊天記錄中發生的錯誤，並且可以建立警示或儀表板來指示或回應特定錯誤的變化。

錯誤類型有幾種。如需詳細資訊，請參閱[監控 Amazon IVS 聊天功能](chat-health.md)。