Error: dynamodb connection timeout
Answered by Rafal Wilinski
What's Causing This Error
This error may occur due to two reasons:
- HTTP Timeouts: These can occur if the AWS SDK cannot establish or maintain HTTP connections with DynamoDB.
- Retries: Sometimes, your operations can time out if the DynamoDB retries take too long. The AWS SDK uses an exponential backoff algorithm to enforce retries, and the AWS SDK auto-retries requests up to 10 times with DynamoDB starting with 50ms for the last retry and 25600ms for the last retry. This means that DynamoDB will take approximately 50 seconds to retry in the worst-case scenario. However, your Lambda function invoked by an API Gateway would have already timed out, causing the request to timeout.
Solution: Here's How To Resolve It
Resolving this error is all about trial and error. For example, you can enforce an HTTP timeout period when initializing the SDK to ensure that your connections are forcefully timed-out after a defined period. The snipper for updating the timeout period is shown below:
import AWS from 'aws-sdk'; const dynamoDb = new AWS.DynamoDB.DocumentClient({ httpOptions: { timeout: 5000 } });
Secondly, consider reducing the retry count from 10 to around 5. By doing so, you can easily find why DynamoDB keeps timing out rather than forcefully retrying until the Lambda function turns out. The snippet for updating the retry count is shown below:
import AWS from 'aws-sdk'; const dynamoDb = new AWS.DynamoDB.DocumentClient({ maxRetries: 3 });
Afterwards, you could inspect CloudWatch logs to get detailed information on the DynamoDB error.
Other Common DynamoDB Errors (with Solutions)
- dynamodb unable to locate credentials
- DynamoDB FilterExpression Not Working
- ExpressionAttributeValues contains invalid value: One or more parameter values were invalid: An AttributeValue may not contain an empty string
- Unable to start DynamoDB Local process
- DynamoDB Query Limit Not Working
- DynamoDB Item Does Not Exist
- ValidationException: Invalid KeyConditionExpression: Attribute name is a reserved keyword;
- comparison operator does not return all attributes dynamodb
- sls dynamodb install not working
- AWS CLI DynamoDB Error Parsing Parameter
- DynamoDB Not Supported Requires @DynamoDBTyped Or @DynamoDBTypeConverted
- dynamodb botocore.exceptions.nocredentialserror unable to locate credentials
- DynamoDB Invalid UpdateExpression Syntax Error Token
- dynamodb map template foreach not working
- cognitoidentitycredentials is not authorized to perform dynamodb describetable
Better DynamoDB experience.
Start your 7-day free trial today
Product Features
DynamoDB Tools
DynamoDB Info
© 2024 Dynobase