Add a Get Note API


#41

I see. Thanks for reporting back.


#42

Why pass a callback to an async function?

export async function main(event, context, callback) {

#43

Oh good catch. You can return right away instead of calling the callback. We need to update this.


#44

I’m getting no response when running

$ serverless invoke local --function create --path mocks/create-event.json

Nothing happens. I only have on IAM identity, and it is configured in the ~/.aws/credentials file. My code is identical to the guide except for the regions which I have changed to us-east-2. An error message would be really helpful, but I don’t know how to produce one. Any advice?


#45

Not sure but you can try setting SLS_DEBUG=* while running the command to see what is going on.


#46

How do we notify aws when there is an error if we don’t throw e in the catch block?


#47

@starkos Same thing for me. Does anyone know why we have to add the “body”: “{“text”:”"}" to the get-event.json file to make it work???


#48

@pobch What do you mean by notify AWS?

@lopezdp Can you elaborate a bit on what you are trying to do? Does the standard get-event.json not work?


#49

@jayair I’m not sure on this point. As my understanding, if we call callback(error) in our lambda functions whenever an error occurred, the error will be notified to AWS service like CloudWatch for logging/monitoring purpose. However, the updated version of this chapter use return instead of callback() function.

Reference: https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-mode-exceptions.html


#50

@jayair in the list-event.json file for the mock input used to test the new list service locally, @starkos and I had to use “body”: “{“text”:”"}" as an attribute in the list-event.json file to get the test to work.

My question is why do we have to use it here and not in other areas?

Thanks!


#51

You can use the callback(error) if you’d like. But we didn’t use it in the past since we are essentially handling the error ourself and we want to control which headers we want to send out. There is a way to tell API Gateway which headers to use in the case of a Lambda exception but it is a bit more complicated.

Prior to this return change, we were simply doing callback(null, response). That is exactly the same as the return response. The way we would send it to CloudWatch would be to console.log(error). Hope that makes sense.


#52

Hmm usually you need the body if it is not a GET request. Can you confirm that it is a GET request?


#53

I am also getting the “Item not found” error, while I can get a record query dynamoDB directly using the same userId and noteId in the get-event.json. Do you have suggestion where may be wrong?

Thanks!


#54

No worries, I had a typo, it works now!

Thanks!