我正在尝试将硬编码数据项放入 DynamoDB。我正在使用 AWS SDK 对象来执行此更新。下面代码中的所有调试“Console.log”都会被打印出来,但最终会打印Task timed out after 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 函数如何通过区域定位表“位置”?-代码似乎没有端点等? - 刚刚根据教程开发。
这就是我所缺少的吗?
请问你能帮忙吗?
最佳答案
我遇到了类似的问题,请尝试将 require 语句放在函数的开头。
const AWS = require("aws-sdk");
const docClient = new AWS.DynamoDB.DocumentClient({ region: 'eu-west-1' });
关于amazon-dynamodb - 任务在 3.00 秒后超时 - 使用 NodeJS 的 Lambda 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47273580/