【发布时间】:2021-02-26 16:42:53
【问题描述】:
我需要更新一项 DynamoDB,这是我的代码。
const Aws = require('aws-sdk');
const endPoint= 'http://dynamodb.us-east-2.amazonaws.com';
const IAm_user_Key=process.env.IAM_USER_KEY;
const IAm_user_Secret=process.env.IAM_USER_SECRET;
Aws.config.update({ accessKeyId:IAm_user_Key,secretAccessKey:IAm_user_Secret,region:'us-east-2',endpoint:endPoint });
var docClient = new Aws.DynamoDB.DocumentClient();
var table = "cards";
var params={
TableName:table,
key:{ "cardid":clientData.data.cardid},
AttributeValue:{"data":clientData.data}
}
docClient.update(params, function(err, data) {
if (err) {
console.error("Unable to add item. Error JSON:", JSON.stringify(err, null, 2));
} else {
console.log("Added item:", JSON.stringify(data, null, 2));
}
})
我在这里运行此代码时遇到问题我的错误。
无法更新项目。错误 JSON:{
"message": "参数中缺少必需的键 'Key'",
"code": "MissingRequiredParameter",
“时间”:“2019-07-20T07:47:06.490Z”
}
但是您可以看到我在 params 中有 Key 对象,但仍在为此苦苦挣扎。
【问题讨论】:
-
如果你想put,你应该使用docClient.update而不是docClient.put。请参阅docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/… 了解更多信息。看起来您正在将更新参数传递给 put 方法。
-
@Armin 对不起我的错误,我编辑我的问题我需要 docClient.update 而不是 put
标签: node.js amazon-web-services amazon-dynamodb