我遇到了AWS DynamoDb JS v2.4.9的问题。我想使用DocumentClient类,而不是低级的DynamoDb类,但是它无法工作。
这样做是可行的:
function testPutItem( callback ) {
var tableName = 'todos';
var params = {
TableName: tableName,
Item: {
user_id: { S : userId },
id: { N : msFromEpoch }, // ms from epoch
title: { S : makeRandomStringWithLength(16) },
completed: { BOOL: false }
}
};
var dynamodb = new AWS.DynamoDB();
dynamodb.putItem(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else {
console.log(data); // successful response
if (callback) callback(data);
}
});
}这不起作用,并为每个属性提供了错误InvalidParameterType: Expected params.Item[attribute] to be a structure --就好像DocumentClient期望得到与DynamoDb相同的输入一样:
function testPutItem( callback ) {
var tableName = 'todos';
var params = {
TableName: tableName,
Item: {
user_id: userId,
id: msFromEpoch,
title: makeRandomStringWithLength(16),
completed: false
}
};
console.log(params);
var docClient = new AWS.DynamoDB.DocumentClient({region: 'us-east-1'});
docClient.put(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else {
console.log(data); // successful response
if (callback) callback(data);
}
});
}有人知道我做错了什么吗?
发布于 2018-04-15 09:17:55
我以前也有同样的问题,
请先尝试使用一个简单的对象,因为它是由于属性中的一些特殊字符造成的,请参见我的示例:
这会产生错误。
InvalidParameterType:期望params.Itemattribute是一个结构
var Item = {
domain: "knewtone.com",
categorie: "<some HTML Object stuff>",
title: "<some HTML stuff>",
html: "<some HTML stuff>""
};但是,当我用格式化的Html (简单字符)替换HTML内容时,它可以工作。
var Item = {
domain: "knewtone.com",
categorie: $(categorie).html(),
title: $(title).html(),
html: $(html).html()
};https://stackoverflow.com/questions/38708555
复制相似问题