Amazon dynamodb 任务在3.00秒后超时-带有nodeJS的Lambda应用程序

Amazon dynamodb 任务在3.00秒后超时-带有nodeJS的Lambda应用程序,amazon-dynamodb,aws-lambda,aws-sdk-nodejs,Amazon Dynamodb,Aws Lambda,Aws Sdk Nodejs,我试图把一个硬编码的数据项放到DynamoDB中。我正在使用AWS SDK对象执行此更新。下面代码中的所有调试“Console.log”都会被打印出来,但最终它会打印出3.00秒后超时的任务 没有对DynamoDB的更新 function updatedb(intent, session, callback) { let country; const repromptText = null; const sessionAttributes = {}; let

我试图把一个硬编码的数据项放到DynamoDB中。我正在使用AWS SDK对象执行此更新。下面代码中的所有调试“Console.log”都会被打印出来,但最终它会打印出3.00秒后超时的任务

没有对DynamoDB的更新

function updatedb(intent, session, callback) {
    let country;
     const repromptText = null;
     const sessionAttributes = {};
     let shouldEndSession = false;

console.log("In the function");
const AWS = require("aws-sdk");
const docClient = new AWS.DynamoDB.DocumentClient({ region: 'eu-west-1' });

var params = {
    TableName: "Location",
    Item: {
        "LocationID": { "S": "11" },
        "Country": { "S": "10" },
        "Description": { "S": "10" },
        "Name": { "S": "10" }
    }
};
console.log("Param loaded & executing the DocClient Put");

docClient.put(params, function (err, data) {
    if (err) {
        speechOutput = 'Update failed';
        console.error("Unable to create table. Error JSON:", JSON.stringify(err, null, 2));
        callback(sessionAttributes,
            buildSpeechletResponse(intent.name, speechOutput, repromptText, shouldEndSession));
    } else {
        console.log("Created table. Table description JSON:", JSON.stringify(data, null, 2));
        speechOutput = 'Update successful';
        callback(sessionAttributes,
            buildSpeechletResponse(intent.name, speechOutput, repromptText, shouldEndSession));
    }
});
}
已检查以下项目

1) DynamoDB中有一个名为“Location”的表 2) DynamoDB和该lambda函数均位于ue-west-1(爱尔兰)中 3) 分配给此Lambda函数的角色可以执行此表上的所有操作。请参阅下面的策略详细信息

{
"Version": "2012-10-17",
"Statement": [
    {
        "Sid": "Stmt1510603004000",
        "Effect": "Allow",
        "Action": [
            "dynamodb:*"
        ],
        "Resource": [
            "arn:aws:dynamodb:eu-west-1:752546663632:table/Location"
        ]
    }
]
}
我的Lambda函数如何仅使用区域定位表“位置”?-刚刚根据教程开发的

这就是我错过的吗


您能帮忙吗?

我相信AWS会根据您的身份以及地区和表格名称来定位表格

我能够使用以下代码成功发布到表:

const AWS = require('aws-sdk');

const dynamoDB = new AWS.DynamoDB({region: 'us-west-2'});

var params = {
  TableName: "my-table",
  Item: {
    "LocationID": { S: "11" },
    "Country": { S: "10" },
    "Description": { S: "10" },
    "Name": { S: "10" }
  }
};

dynamoDB.putItem(params, (err, data) => {
  if (err){
    console.error(err.stack);
  } else {
    console.log(data);
  }
});
如果您实际上可以从CLI发布到表中,那么至少还有一个问题:您似乎不正确地使用了
DocumentClient
类。看起来你把
DynamoDB.putItem
的语法和
DynamoDB.DocumentClient.put
的语法弄混了

如果您注意到了,我的代码直接使用了
DynamoDB
类——基于您所做的,我看不出您为什么不能这样做。否则,您应该更改
项目
对象:

var params = {
  TableName: "my-table",
  Item: {
    "LocationID": "11",
    "Country": "10",
    "Description": "10",
    "Name": "10"
  }
};
我猜您的代码当前出错是因为您试图在要插入字符串的位置插入映射。如果配置了Cloudwatch,则可以检查日志


最后,我没有看到您在代码中使用
callback
。如果您的目的是回应客户呼叫lambda,您应该这样做。根据您的NodeJS版本,lambda可以简单地超时而不返回有用的响应。

我遇到了类似的问题,请尝试将require语句放在函数的开头

const AWS = require("aws-sdk");
const docClient = new AWS.DynamoDB.DocumentClient({ region: 'eu-west-1' });

lambda函数是否设置了超时?否Matt-我认为3秒是默认超时您可以使用CLI放置该项吗?你试过了吗?我创建了一个API网关,成功地上传了Json并在DynamoDB中创建了一个示例记录。我没有尝试使用CLI,以前从未使用过CLI,我使用的是VS2017。如果您认为有帮助,我可以尝试在CLI上获取信息。您的意思是在使用函数之前?@tgf是的,我的node.js代码以下面的代码开头,var aws=require('aws-sdk');var ses=新的aws.ses({region:'us-east-1'});