Skip to content
This repository was archived by the owner on Jun 23, 2021. It is now read-only.

Amazon API Gateway

James Hood edited this page Oct 12, 2019 · 7 revisions

This application uses Amazon API Gateway for the backend REST API. Each REST endpoint is configured to invoke an AWS Lambda function to process each request. This page includes patterns and best practices for working with Amazon API Gateway that are used in this application.

Enable API Logging

Amazon API Gateway supports two types of API logging in CloudWatch: execution logging and access logging.

Execution Logging

Execution logging provides detailed logs for each API request. It can be enabled to log either at the INFO or ERROR level. In test environments, it's good to log at the INFO level for easier debugging. For very high volume APIs, the log level can be set to ERROR in production to reduce cost. API Gateway also has a setting to enable data trace, which logs request and response data to the execution log. This can be helpful in test environments for debugging, but should NOT be enabled in production environments to protect customer data.

Access Logging

Access logging provides a single, highly structured log per request to the API. When used together with CloudWatch Insights, this becomes a powerful way to quickly understand how your API is being used.

For more information on setting up logging in Amazon API Gateway, see the Developer Guide.

Examples in this project:

  1. Enabling logging first requires creating an IAM role that allows API Gateway to push logs to CloudWatch and associating it with API Gateway.
  2. Enabling execution logging at the INFO level with data trace only enabled in non-prod stages.
  3. Enabling access logging first requires defining a log group for the access logs, then enabling it on the API and defining the format of the log.
Clone this wiki locally