Add a Delete Note API

From @jayair on Mon Apr 10 2017 01:00:32 GMT+0000 (UTC)

Link to chapter - http://serverless-stack.com/chapters/add-a-delete-note-api.html

Copied from original issue: https://github.com/AnomalyInnovations/serverless-stack-com/issues/27

From @justDanielMata on Thu Jun 08 2017 12:44:14 GMT+0000 (UTC)

Hello! i have a pretty weird issue with this chapter, all the other endpoints worked fine, but in this one i get a type error: cannot read property ā€˜handlerā€™ of undefinedā€¦it prompts me to run on debug mode, but i have no idea where to put the env variable for that, any help?

From @jayair on Thu Jun 08 2017 14:44:26 GMT+0000 (UTC)

@justDanielMata usually, that means that Serverless is not able to find the handler property in the serverless.yml. Try comparing yours to the one from the chapter and make sure it looks okay - https://github.com/AnomalyInnovations/serverless-stack-demo-api/blob/add-a-delete-note-api/serverless.yml

From @justDanielMata on Fri Jun 09 2017 00:47:13 GMT+0000 (UTC)

thanks for the fast answer, copying the whole functions part on the code seemed to fix it, but i have no idea what happened, fwiw, i wrote the update code myself instead of copy pasting, maybe had identation issues? (i know nothing about yml)

From @jayair on Fri Jun 09 2017 11:32:43 GMT+0000 (UTC)

@justDanielMata Yeah indentations are usually the cause for this. Tabs as opposed to spaces can cause it too.

Hey I just want to add that sometimes a 500 error can occur if the TableName variable in the delete.js file doesnā€™t match the name of the table in the dynamoDB. I know thatā€™s a silly thing to have to say but I was looking around for the error forever until I realized that I had it written in singular fashion on one and plural on the other.

Just wanted to help save some else from that headache.

1 Like

Yeah that is true. Thanks for pointing it out.

Hi @jayair,

Good Day.

I am following serverless-stack for developing a web application. I got an app up and running. I was able to replace AWS Cognito user pool with Google login.

But I am struggling to get the aws-amplify to call an api/lambda.

Config:
aws-amplify config:
It has got userpool, identity pool, region. Should I remove userpool details when I am using google ?

also in api project in serverless.yml, I tried giving the role name (one which was created as part of configuring google in identity pool), but serverless is unable to find the role while deploying.

Can you please help me with the steps ? or some same snippet ?

Thank you,
Vin.

It depends on the type of setup you are using. You can use the User Pool if you want. That just means that your users can login through Google or through the User Pool.

Hi @jayair. I am loving this tutorial. Iā€™m experiencing an issue when trying to update/delete an existing note.
Procedure:
Call aws-api-gateway-cli-test to send a DELETE request to the backend.

npx aws-api-gateway-cli-test
--username='my_test_user' \
-- ...
-- ...
--path-template='/notes/2da001d0-0ef8-11e9-9cd6-3b924645d0ef' \
--method='DELETE' \
--body='{}`

I get the following success response:

Authenticating with User Pool
Getting temporary credentials
Making API request
{ status: 200, statusText: 'OK', data: { status: true } }

But when I look at my DynamoDB table, the row is still there (same for Update note API call). My CORS policy matches the tutorial and so does my serverless.yml. Iā€™m been on this for some time and cannot figure out why it doesnā€™t save. Is there anything else I need to configure on the AWS side? I can create/get/list notes but changes to existing entries seems to not persist.

When I call serverless invoke local --function deleteNote --path mocks/deleteNote-event.json, I also get a successful response (like the one from the chapter), but still no persistence. Any thoughts?

That is super weird. Can you make sure that you are making a request to the right tables? And you are using the right IAM credentials on your local?

Found the issue @jayair. I missed the prepended await keyword for dealing with the promise. Thanks for responding so promptly!

Hey there.

When Iā€™m trying to invoke lokal --function delete I get a Serverless Error:
Function ā€œdeleteā€ doesnā€™t exist in this Service.

All other code seems to be correct even tho Iā€™m writing it myself rather than copy/pasting.

Thank you in advance for your advice and a great tutorial.

//Daniel

If you havenā€™t deployed the delete API yet, you initially need to run serverless deploy. Afterwards, you can
update that single API call/function whenever you want to update it.

Hey, thank you for your response.

Iā€™m following the guide quite to the letter and the delete function has been added in the handler and the delete.js is done properly(hade to both double and tripple-checked my code and nothing really stands out.)

Hi again, nevermind I solved it.
Apparently I created delete:, and not the function: delete:. Imagine what a tab more or less does to the code. Sorry for wasting your time.

Thank you!
/Daniel

Sadly most of these errors are related to YAML formatting. Glad you caught it.

Hey. Iā€™m having the No matching handler found for 'delete' in '/Users/tchris/notes-app-api'. Check your service definition.

There are literally no differences between the tutorial and my actual code, and I already checked the indentation, itā€™s the same as the other handlers.

  delete:
    handler: delete.main
    events:
      - http:
          path: notes/{id}
          method: delete
          cors: true
          authorizer: aws_iam
  
  update:
    handler: update.main
    events:
      - http:
          path: notes/{id}
          method: put
          cors: true
          authorizer: aws_iam

Like my update handlers works, but not delete. Any idea why?

What about the JS file itself? Is that setup correctly?

Thanks for the reply. I just restarted the application and wrote it from scratch again and it worked. Sorry to bother ya!