serverless-stack-demo-api icon indicating copy to clipboard operation
serverless-stack-demo-api copied to clipboard

API calls return `{status: false}` (Error 500) on deploy step

Open elzii opened this issue 9 years ago • 5 comments

Following guide, on this step: http://serverless-stack.com/chapters/deploy-the-apis.html

Running this piece returns tokens just fine

aws cognito-idp admin-initiate-auth \
  --region us-east-1 \
  --user-pool-id $MY_COGNITO_USER_POOL_ID \
  --client-id $MY_COGNITO_APP_CLIENT_ID \
  --auth-flow ADMIN_NO_SRP_AUTH \
  --auth-parameters [email protected],PASSWORD=Passw0rd!

I take the value of idToken returned and put into the example call from the same page of the guide, replacing my values as necessary. Looks similar to:

curl https://<my-app-id>.execute-api.us-west-2.amazonaws.com/prod/notes/ \
  -H "Authorization: <my-identity-token>" \
  -d "{\"content\":\"hello world\",\"attachment\":\"hello.jpg\"}

But I get back a 500 error with the body of {success: false}

Tests run from CLI using event.json worked fine.

How could I debug this? Typically I would toss a console.log around here: https://github.com/AnomalyInnovations/serverless-stack-demo-api/blob/master/get.js#L27

elzii avatar Mar 19 '17 20:03 elzii

Can you double check in your DynamoDB console and ensure the key names for 'notes' table are 'userId' and 'noteId'. Both key names are in camel case with capital 'I'.

fwang avatar Mar 19 '17 22:03 fwang

They are in fact userId and noteId.

I added a line that helps with debugging in this case in the try block.

catch(e) {
  callback(null, failure({status: false, error: e}));
}

This aids in debugging a bit when testing the production API. I'm seeing now it's a AccessDeniedException. The IAM user access/key I am using however has full admin access. I wonder if the mixmatch of regions I am using is affecting it?

I will follow up.

elzii avatar Mar 20 '17 04:03 elzii

I see. Were you able to get a 200 response when invoking the lambda functions locally?

serverless webpack invoke

fwang avatar Mar 20 '17 04:03 fwang

I was having the same issue. Mine was due to a region mismatch since my DynamoDB table was created in us-west-2 while the lambda function was set-up for us-east-1.

Specifically, insert the region where your DyanmoDB table is created in the following line Resource: "arn:aws:dynamodb:DYNAMO_DB_REGION_HERE:*:*" in serverless.yml

abagasra98 avatar Apr 04 '17 03:04 abagasra98

Closing this.

jayair avatar Jun 12 '17 17:06 jayair