I'm seeing higher latency when clients send requests to my edge-optimized API in Amazon API Gateway. How do I find the source of the latency?

To find the source of latency for an edge-optimized API, determine the amount of time each part (each of these steps) of the connection path takes:

Important: These steps apply to edge-optimized APIs, but not regional APIs. Because edge-optimized APIs are accessed through an Amazon CloudFront distribution, the connection path includes CloudFront steps.

  1. Start of connection to the DNS name resolution.
  2. Start of connection to the TCP handshake to connect to CloudFront.
  3. Start of connection to the SSL handshake to connect to CloudFront.
  4. Start of connection to sending the client HTTP request to CloudFront.
  5. Start of connection to the first byte transferred from CloudFront.
  6. Total time for the request and response to the API.
  7. API Gateway processing the request and responding to the CloudFront edge location.
  8. Integration endpoint responding to the HTTP request from API Gateway.
  9. Between API Gateway responding to the CloudFront edge location, and CloudFront responding to the client.

Use curl for latency

To get the duration of several steps in the process, use the curl_for_latency script from the Amazon Web Services - Labs GitHub website.

Note: Be sure to update the URL, HTTP method, and parameters to match the details for your API.

The script returns the time for these steps:

  1. Start of connection to the DNS name resolution: Value for "time_namelookup."
  2. Start of connection to the TCP handshake to connect to CloudFront: Value for "time_connect."
  3. Start of connection to the SSL handshake to connect to CloudFront: Value for "time_appconnect."
  4. Start of connection to sending the client HTTP request to CloudFront: Value for "time_pretransfer."
  5. Start of connection to the first byte transferred from CloudFront: Value for "time_starttransfer."
  6. Total time for the request and response to the API: Value for "time_total."

Check the time for API Gateway processing the request and responding to the CloudFront edge location

To get the time it takes for API Gateway to process the request and respond to the CloudFront edge location, use the Amazon CloudWatch console to view the Latency metric from API Gateway. This metric gives an aggregate view on all requests to the stage during a certain timeframe.

In the CloudWatch console, configure the Latency metrics graph for 1-minute interval and Maximum to see the longest processing time within a one-minute timeframe.

Check the time for the integration endpoint responding to the HTTP request from API Gateway

To get the time it takes for the integration endpoint to respond to the HTTP request from API Gateway, use the CloudWatch console to view the IntegrationLatency metric. This metric gives an aggregate view on all requests to the integration request endpoint and the time it takes for the endpoint to respond to the request from API Gateway. Configure the IntegrationLatency metrics graph for 1-minute interval and Maximum.

As another option, if you have CloudWatch Logs enabled, review your CloudWatch Logs for a line item that contains information similar to the following:

Received response. Integration latency: 325 ms

Note: If you're using AWS Lambda and you see a high metric for integration latency, review the Lambda function's CloudWatch Logs to troubleshoot the increase in the function's duration. Because cold starts in Lambda functions aren't recorded in the function's duration metric, you might see that the integration latency is longer than the duration of the function. To see the duration of your function with a cold start, use AWS X-Ray.

Check the time between API Gateway responding to the CloudFront edge location and CloudFront responding to the client

To get the time between API Gateway responding to the CloudFront edge location and CloudFront responding back to the client, follow these steps:

  1. Take the time for "Total time for the request and response to the API."
  2. Subtract the time for "Start of connection to sending the client HTTP request to CloudFront."
  3. Subtract the time for "API Gateway processing the request and responding to the CloudFront edge location."
  4. The result is the time between API Gateway responding to the CloudFront edge location and CloudFront responding back to the client.

Did this page help you? Yes | No

Back to the AWS Support Knowledge Center

Need help? Visit the AWS Support Center

Published: 2018-12-12