I am trying to add a Todo to my DynamoDB from my ReactApp, but I always get Key errors, or replace error which means params are not being passed.
I am using Axios to send the request:
export const addTodo = createAsyncThunk(
'todoApp/todos/addTodo',
async (todo, { dispatch, getState }) => {
const response = await axios.post('api.us-west-2.amazonaws.com/prod/', {
Item: {
id:todo.key1,
title: todo.key2,
notes: todo.key3,
startDate: todo.key4,
dueDate: todo.key5,
completed: todo.key6,
starred: todo.key7,
important: todo.key8,
deleted: todo.key9,
labels: todo.key10
},
});
const data = await response.data;
dispatch(getTodos());
return data;
}
);
and here is my Lambda function to add the item to DynamoDB: This is working, I tested from Lambda:
exports.handler = (event, context, callback) => {
console.log("Processing...");
const params = {
Item: {
id:event.key1,
title: event.key2,
notes: event.key3,
startDate: event.key4,
dueDate: event.key5,
completed: event.key6,
starred: event.key7,
important: event.key8,
deleted: event.key9,
labels: event.key10
},
TableName: "Todo"
};
const response = {
statusCode: 200,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Credentials': true,
},
body: JSON.stringify('Done'),
};
docClient.put(params, function(err, data) {
if(err){
callback(err, null);
} else {
callback(null, data);
}
})
};
When I play around the code, I usually get two ERRORS:
Warning: Each child in a list should have a unique "key" prop.
or
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'replace')