How do I troubleshoot intermittent timeout errors in Amazon DynamoDB?
Last updated: 2022-08-19
When I use AWS SDK to interact with Amazon DynamoDB, I see intermittent connection timeout or request timeout errors, such as the following:
- Unable to execute HTTP request: Connect to dynamodb.xx-xxxx-x.amazonaws.com:443 [dynamodb.us-east-1.amazonaws.com/x.xxx.xxx.x] failed: connect timed out
- com.amazonaws.SdkClientException: Unable to execute HTTP request. Request did not complete before the request timeout configuration
When you make an API call to DynamoDB, the following happens:
- Your application resolves the DynamoDB endpoint using your local DNS server.
- After getting the IP address of the DynamoDB endpoint, the application connects to the endpoint and makes the API call.
- The endpoint routes this call to one of the backend nodes.
During this process, the API call might intermittently result in connection timeout or request timeout errors. In most cases, the timeout error results from a client-side error that occurs before the API call reaches DynamoDB due to network issues or incorrect SDK configurations on the client side.
To troubleshoot these errors, do the following:
- Tune the SDK HTTP client parameters according to your use case and application SLA. In addition to tuning connectionTimeout, requestTimeout, and maxRetries, you can also tune clientExecutionTimeout and socketTimeout. The ClientExecutionTimeout parameter indicates the maximum allowed total time spent to perform an end-to-end operation and receive the desired response, including any retries that might occur. Be sure that you set this value to be greater than the individual requestTimeout value. The socketTimeout parameter indicates the maximum amount of time that the HTTP client waits to receive a response from an already established TCP connection. For more information, see Tuning AWS Java SDK HTTP request settings for latency-aware Amazon DynamoDB applications.
- Be sure to send constant traffic or reuse connections. When you're not making requests, consider having the client send dummy traffic to a DynamoDB table. Or, you can reuse client connections or use connection pooling. These techniques keep internal caches warm, which helps to reduce the latency and avoid timeout errors on client side. For example, see Reusing connections with Keep-Alive in Node.js.
- View your Amazon Virtual Private Cloud (Amazon VPC) flow logs to check if there was incoming traffic to DynamoDB during the timeframe when you got the error. You can also use AWS X-Ray to monitor the latency of your application.