Link to chapter - http://serverless-stack.com/chapters/add-a-list-all-the-notes-api.html
One suggestion - why not name the event.json files after the function they are testing, that way a library of them can be maintained in case of further testing? eg:
serverless webpack invoke --function list --path -list-event.json
Ah yeah that's not a bad idea. In the case of the tutorial, we just use it for one off testing cases and don't commit it to the repo - https://github.com/AnomalyInnovations/serverless-stack-demo-api/blob/master/.gitignore#L40
Created a PR for this. Updated instructions to test functions coming from a mocks/ directory for cleaner structure.
I'm following the serverless tutorial, and when it comes to this function I get a "Cannot read property 'id' of undefined" error.
The previous tests ran just fine.
I tried to look for a solution but I found nothing. Do I need to open a new issue?
Nevermind. Tried again today without changing anything and works flawlessly. Stranger things, season 3 :)
@bimbo1989 Thanks for reporting back.
Hi, apologies if this doesn't belong here because of the modification I made, but I'm trying to write the "list all notes" API with a minor modification and running into an issue:
In list.js, I have this:
const params = {
TableName: "notes",
IndexName: "teacher-index",
KeyConditionExpression: "teacher = :teacher",
ExpressionAttributeValues: {
":teacher": event.pathParameters.teacher
}
};
I am trying to retrieve all the notes that are assigned to a specific teacher (instead of the user), and the teacher field is NOT part of the key (partition or sort). So, I created an index (teacher-index) and referenced it above.
This works, with the list-event.json below:
{
"pathParameters": {
"teacher": "Bill"
}
}
It successfully returns all the notes that have the teacher field set to "Bill".
However, this does NOT work:
{
"pathParameters": {
"teacher": "Omair Hamid"
}
}
It returns an empty set, even though there are several notes that have the teacher field set to "Omair Hamid".
Are spaces something that I cannot have? Do I need to escape them? Am I building the list-event.json incorrectly or the list.js file?
@omairhamid That looks okay and it should work. Can you just make sure that that it is stored and queried with a space in the middle and not a tab or something? Since Bill is working, it should be fine.
This issue was moved to https://discourse.serverless-stack.com/t/comments-add-a-list-all-the-notes-api/147