包含我的 Cognito 信息的 AWS 教程就像一个魅力。但是,当我出于某种原因将其移植到不同的 HTML 文件时,put 不起作用。我可以使用相同的列表函数来查询我的帐户,这表明我的凭据有效(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);
}
});
}