包含我的 Cognito 信息的 AWS 教程就像一个魅力。 但是,当我由于某种原因将其移植到不同的 HTML 文件时,放置不起作用。 我可以使用相同的列表函数来查询我的帐户,这表明我的凭据有效(dynamodb 和 docClient 具有相同的权限? 我一直在用头撞屏幕,似乎无法在数据库中输入一行。 这是我缺少键值的 b/c 的 NoSQL 问题吗?
var dynamodb = new AWS.DynamoDB();
var docClient = new AWS.DynamoDB.DocumentClient();
var my_form = {};
function getFormData(log_date,notes){
my_form.log_date=document.getElementById('log_date').value;
my_form.notes=document.getElementById('parent_notes').value;
console.log("I got form data of "+my_form.log_date+" and "+my_form.notes);
/* some other fields */
/* now call ur function by passing the above values */
}
这部分不起作用:(
function createItem() {
getFormData();
console.log("in createItem:"+my_form.log_date+" and "+my_form.notes);
var params = {
TableName :"Infant_Logs",
Item:{
"year": 2011,
"title": "testing",
"Date": "something",
"Name": "Daniel",
"Notes": "none"
/*"info":{
"plot": "Nothing happens at all.",
"rating": 0
}*/
}
};
console.log("I am params: "+JSON.stringify(params));
docClient.put(params, function(err, data) {
if (err) {
//console.log("Unable to add item: "+"n"+JSON.stringify(err, undefined,2));
document.getElementById('textarea').innerHTML = "Unable to add item: " + "n" + JSON.stringify(err, undefined, 2);
} else {
//console.log("PutItem succeeded: "+"n"+JSON.stringify(data,undefined,2));
document.getElementById('textarea').innerHTML = "PutItem succeeded: " + "n" + JSON.stringify(data, undefined, 2);
}
});
console.log("The end of creation");
}
这部分工作
function listMovies() {
var params = {};
dynamodb.listTables(params, function(err, data) {
if (err){
console.log("I totally err");
document.getElementById('textarea').innerHTML = "Unable to list tables: " + "n" + JSON.stringify(err, undefined, 2);
}
else{
console.log("I totally werk "+JSON.stringify(data,undefined,2));
document.getElementById('textarea').innerHTML = "List of tables: " + "n" + JSON.stringify(data, undefined, 2);
}
});
}
我想
我知道发生了什么。 NoSQL格式需要一个字符串。 javascript变量是对象(或其他东西(,所以一旦我添加 .toString()
它开始弹出。我仍然没有看到成功日志,但至少它正在数据库中填充。耸肩