I have a simple logic where I want to INSERT
record in the table using AWS.DynamoDB.DocumentClient
. Below is code which I am using. Here, I am noticing that .put
is updating the record and not sure why.
While checking the logs in CW, I am not seeing any error so not sure what am I missing here.
Code:
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;
});
}