In this quick lesson we're going to expand our todoHandler.ts
lambda function in order to implement a addTodoItem
method with AWS.DynamoDB.DocumentClient
put
operation
When testing the api in insomnia or postman with a put request, my response is 500 error "todo is missing" even though it successfully adds the item to the database.
When I mouse over the 'todo' in the return statement in:
if (httpMethod === "POST") {
const todo = await addTodoItem(data);
return todo
? createResponse(${todo} added to the database
)
: createResponse("Todo is missing", 500);
}
I'm getting a warning in my editor (VScode) that "an expression of type 'void' cannot be tested for truthiness". I suspect that's the cause however I'm not sure how to fix it. I'll update if I find a solution.
I was missing the last "return todo;" statement in the addTodoItem function. Makes sense it couldn't be evaluated.
todoHandler.handler lambda function cannot be found when invoked
It only worked after I compiled with tsc and todoHandler.js
is generated.