In this article we will see how to enable traffic monitoring for AWS API Gateway using cloudwatch logs.

How to setup Detailed Tracing in AWS REST API Gateway

  1. Create an IAM role to send logs to CloudWatch

  1. Add the IAM role in the API Gateway console

|| The CloudWatch Logs role is an AWS Region-level configuration that you use with all the APIs in the Region. If you create multiple APIs across different Regions, then complete the preceding steps in each Region.

  1. Turn on API logging and stage the API

($context.requestId) Access Log {"httpMethod":"$context.httpMethod", "path":"$context.path", "status":"$context.status", "protocol":"$context.protocol", "domain":"$context.domainName"}
  1. Test your logging setup

| To send a new request to your API, use your client application or tools, such as the Postman.

How to setup Access Logging in AWS HTTP API Gateway

  1. Create the logGroup and keep the log group name and ARN handy. Please ensure to create the log group name as: API-Gateway-Execution-Logs_gatewayID/stageName. Example: If the gatewayID is z3xiu18cq2 and stage name is test, then, create the log group name MUST be API-Gateway-Execution-Logs_z3xiu18cq2/test

  2. Sign in to the API Gateway console at https://console.aws.amazon.com/apigateway

  3. Choose an HTTP API

  4. Under the Monitor tab in the primary navigation panel, choose Logging.

  5. Select a stage to activate logging and choose Select.

  6. Choose Edit to activate access logging.

  7. Turn on Access logging

($context.requestId) Access Log {"httpMethod":"$context.httpMethod", "path":"$context.path", "status":"$context.status", "protocol":"$context.protocol", "domain":"$context.domainName"}
  1. Choose Save.

  2. Test your logging setup

| To send a new request to your API, use your client application or tools, such as the Postman.

How to setup AWS Access Keys

It's a two step process which are detailed below:

Step 1: Create IAM User

Step 2: Create Access Key

||| If you lose or forget your secret access key, you cannot retrieve it. Instead, create a new access key and make the old key inactive.