DynamoDB:无法更新节点 js 中的 dynamoDB 项目



我是dynamoDB的新手,我正在尝试更新并将项目获取到db,但我不能,总是得到"提供的关键元素与架构不匹配">

这是我的 dynamoDB 的无服务器.yml 代码

resources:
Resources:
TodosDynamoDbTable:
Type: 'AWS::DynamoDB::Table'
DeletionPolicy: Retain
Properties:
AttributeDefinitions:
-
AttributeName: id
AttributeType: S
-
AttributeName: in_organization_id
AttributeType: S
-
AttributeName: sp_customer_id
AttributeType: S
-
AttributeName: qb_customer_id
AttributeType: S
KeySchema:
-
AttributeName: id
KeyType: HASH
-
AttributeName: in_organization_id
KeyType: RANGE
-
AttributeName: sp_customer_id
KeyType: RANGE
-
AttributeName: qb_customer_id
KeyType: RANGE
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
TableName: 'insightly'

这是我的更新方法

/* Update Record in DB */
this.UpdateDB = (event) => {
return new Promise(async (resolve, reject) => {
try {
const data = event;
const params = {
TableName: process.env.TABLE_NAME,          
Key: {
in_organization_id : data.in_organization_id
},     
UpdateExpression: "set qb_customer_id = :qb_customer_id",
ExpressionAttributeValues:{
":qb_customer_id":data.qb_customer_id
},
ReturnValues:"UPDATED_NEW"}
const response=await dynamoDb.update(params).promise();
resolve(response);
} catch (err) {
reject(err.message);
}
});
};

像明智一样,我有获取方法来获取项目

/* Get/Check Org ID from DB */
this.checkOrgID = (OrgID) => {
return new Promise(async (resolve, reject) => {
try {
const params = {
TableName: process.env.TABLE_NAME,
Key: {in_organization_id :OrgID}
};
const response = await dynamoDb.get(params).promise();
resolve(response);
} catch (err) {
reject(err.message);
}
});
};

但它总是给我错误。请帮助我找出解决方案。提前谢谢。

如果您使用的是适用于 Javascript 的 AWS 开发工具包,则可以使用以下信息:

const document = { 
document_id: "1",
name: "John",
lastname: "Snow" 
}

document_id是我的钥匙

return dynamodb
.put({ TableName: 'tableName', Item: document })
.promise();

最新更新