【发布时间】:2020-12-21 21:35:15
【问题描述】:
我有一个简单的逻辑,我想使用AWS.DynamoDB.DocumentClient 在表中记录INSERT。下面是我正在使用的代码。在这里,我注意到.put 正在更新记录,但不知道为什么。
在检查 CW 中的日志时,我没有看到任何错误,所以不确定我在这里遗漏了什么。
代码:
async addEvent(incomingModel: MyModel): Promise <MyModel> {
const dynamoModel: MyModel = {
fieldOne: incomingModel.fieldOne,
fieldTwo: incomingModel.fieldTwo,
"One#two#three": `${incomingModel.one}#${incomingModel.two}#${incomingModel.three}`,
fieldThree: incomingModel.fieldThree,
fieldFour: incomingModel.fieldFour,
};
var params = {
TableName: 'Table',
Item: dynamoModel,
};
return this.documentClient
.put(params)
.then((data) => {
this.logger.debug(
"Response received from Dynamo after adding an incomingModel",
data,
this.constructor.name,
);
return data as MyModel;
})
.catch((error) => {
const errorMessage = JSON.stringify(error);
this.logger.error(
`Error creating incomingModel with body of ${errorMessage}`,
error,
this.constructor.name,
);
throw error;
});
}
【问题讨论】:
标签: node.js typescript amazon-web-services amazon-dynamodb documentclient