【问题标题】:Dynamodb call DocumentClient.get in AWS Lamdba is timing outAWS Lambda 中的 Dynamodb 调用 DocumentClient.get 超时
【发布时间】:2021-03-05 13:58:27
【问题描述】:

以下 lambda 函数超时(通过 WSS API 网关调用) 类似的调用已在本地 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' };      
  
};

'''

以下是对应的 CloudWatch 日志。

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

2020-11-22T19:11:23.781Z 234b8e95-0555-45d6-811f-c6fa4d354e61 INFO 进入处理程序

END 请求 ID:234b8e95-0555-45d6-811f-c6fa4d354e61

REPORT RequestId:234b8e95-0555-45d6-811f-c6fa4d354e61 持续时间:10010.57 毫秒计费持续时间:10000 毫秒内存大小:128 MB 最大已用内存:85 MB 初始化持续时间:403.44 毫秒

2020-11-22T19:11:33.790Z 234b8e95-0555-45d6-811f-c6fa4d354e61 任务在 10.01 秒后超时

【问题讨论】:

  • 您的 lambda 超时设置为多少?听起来 lambda 会在 10 秒后超时。
  • 设置为 10 秒。即使我将其更改为 5 分钟,它仍然超时。 Give 表只有 2 行,我原以为 1 秒就足够了。
  • Lambda 的角色是否允许它访问 DynamoDB 表?
  • Lambda 在 VPC 中运行?它需要route to the internet 或 DynamoDB 端点。

标签: amazon-web-services lambda aws-lambda amazon-dynamodb


【解决方案1】:

谢谢,@jarmod,Lambda 在 VPC 中。

我没有让它访问互联网,而是向 dynamo DB 添加了一个 VPC 端点。

我在 DocumentClient 配置中添加了一个端点,现在我的 Lambda 能够连接到 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
  
});

'''

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-22
    • 2016-09-04
    • 2016-09-24
    • 1970-01-01
    • 2021-01-30
    • 2021-04-01
    相关资源
    最近更新 更多