Ad

Lambda Starts Timing Out Randomly When Communicating With DynamoDB

I have a Node.js Lambda code base that talks to tiny dataset in DynamoDB (less than 400 byte each). Every now and then the function will time out over 5 minutes whilst doing a get() request to DynamoDB (via dynamoDbdAWS.DynamoDB.DocumentClient();).

The problem is it's completely random as to when this issue will occur but when it works it take ~2 second from a cold start, so taking over 5 minutes to run makes no sense and at random points.

  • It's a dev environment so only myself is using this, and I'm doing maybe 10 requests a day
  • context.callbackWaitsForEmptyEventLoop = false; has been set
  • Memory allocation never exceeds 45MB (128MB set)
  • I'm testing directly in Lambda
  • The code is deployed via Serverless
  • When testing, using Serverless, locally it works whilst the Lambda fails

I've inherited this project but have a good understanding of the architecture around it and it's fairly simple but I've not done much work with Lambda before.

Any ideas what I should look for or any known issues will be a massive help.

Ad

Answer

It sounds like one (or more) of the VPC subnets the Lambda function is configured to run in doesn't have a route to a NAT Gateway (or an AWS PrivateLink configuration). So whenever that subnet is used by the Lambda function it is unable to access the AWS API.

If the Lambda function doesn't actually need to access any resources in the VPC then it is much better to not configure it to use the VPC at all.

Ad
source: stackoverflow.com
Ad