Add a Delete Note API


#1

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


#2

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?


#3

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


#4

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)


#5

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.


#6

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.


#7

Yeah that is true. Thanks for pointing it out.


#8

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.


#9

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.


#10

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?


#11

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?


#12

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


#13

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


#14

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.


#15

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.)


#16

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


#17

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