【发布时间】:2018-02-26 05:08:16
【问题描述】:
我正在尝试将硬编码的数据项放入 DynamoDB。我正在使用 AWS 开发工具包对象来执行此更新。下面代码中的所有调试“Console.log”都被打印出来,但最终它打印出Task timed out after 3.00 seconds
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 函数如何仅使用区域定位表“位置”?- 代码似乎没有端点等? - 只是根据教程开发的。
这是我想念的吗?
你能帮忙吗?
【问题讨论】:
-
你的 lambda 函数是否设置了超时时间?
-
No Matt - 我认为 3 秒是默认超时
-
您可以使用 CLI 放置项目吗?你试过吗?
-
我创建了一个 API 网关,并且成功上传了 Json 并在 DynamoDB 中创建了一个示例记录。我没有尝试使用 CLI,之前从未使用过 CLI,我使用的是 VS 2017。如果您认为这会有所帮助,我可以尝试获取有关 CLI 的信息。
标签: amazon-dynamodb aws-lambda aws-sdk-nodejs