0
votes

Following lambda function is timing out (called via WSS API Gateway) Similar calls have worked on local DynamoDB

'''

var AWS = require("aws-sdk");
var docClient = new AWS.DynamoDB.DocumentClient({
  region: "ap-south-1",  
  httpOptions: {
    timeout: 5000
  },
  maxRetries: 3
  
});

exports.handler = async function(event, context) 
{
  
  console.log("Entering handler");
  
  try 
  {
    
     var params = 
     {
        TableName : "meeting_info",
        Key:{
          "meeting_id" :"100-200-300"
            
        }
    };
    
    try 
    {
      var data = await docClient.get(params).promise();
      
      console.log(data);
      
    } catch (e) {
      console.error(e);
    }
  } 
  catch (err) 
  {
      console.error("meeting_connections",err);
      return { statusCode: 500.4, body: 'Failed to connect: ' + JSON.stringify(err) };
  }
 
  return { statusCode: 200, body: 'Connected' };      
  
};

'''

Following are the corresponding CloudWatch logs.

START RequestId: 234b8e95-0555-45d6-811f-c6fa4d354e61 Version: $LATEST

2020-11-22T19:11:23.781Z 234b8e95-0555-45d6-811f-c6fa4d354e61 INFO Entering handler

END RequestId: 234b8e95-0555-45d6-811f-c6fa4d354e61

REPORT RequestId: 234b8e95-0555-45d6-811f-c6fa4d354e61 Duration: 10010.57 ms Billed Duration: 10000 ms Memory Size: 128 MB Max Memory Used: 85 MB Init Duration: 403.44 ms

2020-11-22T19:11:33.790Z 234b8e95-0555-45d6-811f-c6fa4d354e61 Task timed out after 10.01 seconds

1
What is your lambda timeout set to? Sounds like lambda is timing out after 10 seconds.hvaughan3
it is set to 10 seconds.. Even if I change it to 5 minutes, it still times out. Give table has only 2 rows, I was expecting that 1 second was more than enough.Sandeep Dixit
Does the Lambda's role give it access to the the DynamoDB table?Ryan H Lewis
Lambda running in VPC? It needs a route to the internet or a DynamoDB endpoint.jarmod

1 Answers

0
votes

Thanks, @jarmod, Lambda was in a VPC.

Rather than giving it access to the internet, I added a VPC endpoint to dynamo DB.

I added an endpoint to the DocumentClient configuration, now my Lambda is able to connect to DB.

''' var AWS = require("aws-sdk");

var docClient = new AWS.DynamoDB.DocumentClient({
  region: "ap-south-1",  
  endpoint:"https://dynamodb.ap-south-1.amazonaws.com",
  httpOptions: {
    timeout: 5000
  },
  maxRetries: 3
  
});

'''