Add an API to List All the Notes

Link to chapter — https://serverless-stack.com/chapters/add-an-api-to-list-all-the-notes.html

When clicking Send the console is not displaying anything, like shown in the guide. The console displays nothing. However it is shown in the terminal in VS Code.

I believe it is because the handler is invoking an async anonymous function which does not return to the console browser. Yet, this is inconsistent with what the guide shows.

I found the reason for this is I was running the debugger during that execution. Run normal without the debugger and output goes to the console.

1 Like

Hey Folks,

Im trying to follow the tutorial, but i got stuck on this part.

This is the error i get when calling GET /notes:

    "error": "One or more parameter values are not valid. The AttributeValue for a key attribute cannot contain an empty string value. Key: noteId"

This is the code in list.ts (its the same as in the tutorial in my opinion, but maybe i just made a typo somewhere, so just in case, im pasting):

import { Table } from "sst/node/table";
import handler from "@notes/core/handler";
import dynamoDb from "@notes/core/dynamodb";

export const main = handler(async (event) => {
    const params = {
        TableName: Table.Notes.tableName,
        KeyConditionExpression: "userId = :userId",
        ExpressionAttributeValues: {
            ":userId": "123"
        }
    }

    const result = await dynamoDb.query(params)

    return JSON.stringify(result.Items)
})

Im not sure why index endpoint would need noteId to display notes for the userId, but i think it might have something to do with how the table is being created:

 const table = new Table(stack, "Notes", {
    fields: {
      userId: "string",
      noteId: "string",
    },
    primaryIndex: { partitionKey: "userId", sortKey: "noteId" },
  });

My theory is probably wrong because i didnt fully understand the sortkey/primarykey/index explanation yet.

Did anyone had similar error? I’ve seen someone having 500 returned, but thats definietly not the same. It looks like a legit error from DynamoDB.

Cheers, Pawel