I have the following Lambda function to delete an item from my DynamoDB.
const AWS = require("aws-sdk");
AWS.config.update({ region: "us-west-2" });
var docClient = new AWS.DynamoDB.DocumentClient();
var deleteContact = function(event,callback) {
var params = {
TableName:"Contacts",
Key:{
id: event.id
},
ConditionExpression: "set event.id = :id",
ExpressionAttributeValues: {
":id": event.id
}
};
console.log("Attempting a conditional delete...");
docClient.delete(params, function(err, data) {
if (err) {
console.error("Unable to delete item. Error JSON:", JSON.stringify(err, null, 2));
} else {
console.log("DeleteItem succeeded:", JSON.stringify(data, null, 2));
}
});
};
deleteContact();
and here is the code in my react app which is requesting:
export const removeContact = createAsyncThunk(
'contactsApp/contacts/removeContact',
async (contactId, { dispatch, getState }) => {
await axios.post('https://API.amazonaws.com/prod', {
key1: `${contactId}`
});
console.log(contactId)
return contactId;
}
);
Currently, code works and deletes the parameters in the row. But the problem is it will not remove the id from the DynamoDB table. So everything will be deleted EXCEPT id.
As result, I would have GHOST items in my DynamoDB table:
DynamoDB screenshot