

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

# 在 CloudWatch 主控台中檢視 API Gateway 日誌事件
<a name="view-cloudwatch-log-events-in-cloudwatch-console"></a>

下一節說明必要的先決條件，以及如何在 CloudWatch 主控台檢視 API Gateway 日誌事件。

## 先決條件
<a name="view-cloudwatch-log-event-prerequisites"></a>

1. 您必須擁有在 API Gateway 中建立的 API。請遵循中的說明進行[在 APIs Gateway 中開發 REST API](rest-api-develop.md)

1. 您必須至少已部署並調用一次 API。請遵循[在 API Gateway 中部署 REST API](how-to-deploy-api.md)和[在 API Gateway 中調用 REST API](how-to-call-api.md)中的說明進行。

1. 您必須已針對階段啟用 CloudWatch 日誌。請遵循中的說明進行[在 API Gateway 中設定 REST API 的 CloudWatch 記錄功能](set-up-logging.md)

## 使用 CloudWatch 主控台檢視記錄的 API 請求與回應
<a name="view-cloudwatch-log-event"></a>

1. 在 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 如有需要，請變更 AWS 區域。從導覽列中，選取 AWS 資源所在的區域。如需詳細資訊，請參閱 [ 區域與端點](https://docs.aws.amazon.com/general/latest/gr/rande.html)。

1. 在導覽窗格中依序選擇 **Logs** (日誌)、**Log groups** (日誌群組)。

1. 在 **Log Groups (日誌群組)** 資料表下，選擇 **API-Gateway-Execution-Logs\$1\$1rest-api-id\$1/\$1stage-name\$1** 名稱的日誌群組。

1.  在 **Log Streams (日誌串流)** 資料表下，選擇一個日誌串流。您可以使用時間戳記協助尋找感興趣的日誌串流。

1. 選擇 **Text (文字)** 以檢視原始文字，或選擇 **Row (資料列)** 以逐列檢視事件。

**重要**  
 CloudWatch 可讓您刪除日誌群組或串流。不要手動刪除 API Gateway API 日誌群組或串流；讓 API Gateway 管理這些資源。手動刪除日誌群組或串流可能會導致 API 請求與回應不被記錄。如果發生這種情況，您可以刪除 API 的整個日誌群組，然後重新部署 API。這是因為 API Gateway 會針對部署 API 時的 API 階段，來建立日誌群組或日誌串流。