New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comments: Test the APIs #112

Closed
jayair opened this Issue Jul 19, 2017 · 317 comments

Comments

Projects
None yet
@jayair
Copy link
Member

jayair commented Jul 19, 2017

@jayair jayair added the Discussion label Jul 19, 2017

@yashg5

This comment has been minimized.

Copy link

yashg5 commented Jul 20, 2017

Can you give us example screen shots to test API with postman using AWS signature? thanks in advance

@jayair

This comment has been minimized.

Copy link
Member

jayair commented Jul 20, 2017

@yashg5 I'm not too familiar with using Postman. Perhaps somebody else can give it a try.

@marshallbunch

This comment has been minimized.

Copy link

marshallbunch commented Jul 20, 2017

First off, thanks a ton for your tutorials. I went through the previous and now the revised. You're doing great work.

For some reason I'm getting an error when testing the apis:

Error: Invalid UserPoolId format.

at new CognitoUserPool (C:\Users\proet\AppData\Roaming\npm\node_modules\aws-api-gateway-cli-test\node_modules\amazon-cognito-identity-js\lib\CognitoUserPool.js:56:13)
at authenticate (C:\Users\proet\AppData\Roaming\npm\node_modules\aws-api-gateway-cli-test\index.js:70:18)
at Object.<anonymous> (C:\Users\proet\AppData\Roaming\npm\node_modules\aws-api-gateway-cli-test\index.js:155:1)

I can't really think of a reason why I would be experiencing this problem. I've had no problems for any of the tests I've done so far that used the same user-pool-id.

Any chance you could provide a sample apig-test call with actual values?

@jayair

This comment has been minimized.

Copy link
Member

jayair commented Jul 20, 2017

@marshallbunch Here is a sample one that I was using. I altered some of the values around but the format should be like so.

apig-test \
--username='admin@example.com' \
--password='Passw0rd!' \
--user-pool-id='us-east-1_YBhdXYvix' \
--app-client-id='29qwoeorti0ctjkur5h91lkw5g' \
--cognito-region='us-east-1' \
--identity-pool-id='us-east-1:565cc505-5486-4278-bf0f-9736p9apq8m5' \
--invoke-url='https://w5z1hluqmp5.execute-api.us-east-1.amazonaws.com/test' \
--api-gateway-region='us-east-1' \
--path-template='/notes' \
--method='POST' \
--body='{"content":"hello world","attachment":"hello.jpg"}'
@marshallbunch

This comment has been minimized.

Copy link

marshallbunch commented Jul 20, 2017

No cigar. Won't make it past the user-pool-id.

@jayair

This comment has been minimized.

Copy link
Member

jayair commented Jul 20, 2017

@marshallbunch Hmm can I see the complete output from the command?

@marshallbunch

This comment has been minimized.

Copy link

marshallbunch commented Jul 20, 2017

Sure:

C:\Users\proet\AppData\Roaming\npm\node_modules\aws-api-gateway-cli-test\node_modules\amazon-cognito-identity-js\lib\CognitoUserPool.js:56
      throw new Error('Invalid UserPoolId format.');
      ^

Error: Invalid UserPoolId format.
    at new CognitoUserPool (C:\Users\proet\AppData\Roaming\npm\node_modules\aws-api-gateway-cli-test\node_modules\amazon-cognito-identity-js\lib\CognitoUserPool.js:56:13)
    at authenticate (C:\Users\proet\AppData\Roaming\npm\node_modules\aws-api-gateway-cli-test\index.js:70:18)
    at Object.<anonymous> (C:\Users\proet\AppData\Roaming\npm\node_modules\aws-api-gateway-cli-test\index.js:155:1)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:427:7)
@manubhat90

This comment has been minimized.

Copy link

manubhat90 commented Jul 20, 2017

For beginners it might be helpful to specify that YOUR_API_GATEWAY_URL should include the stage-name (prod in the example).

"https://ly55wbovq4.execute-api.us-east-1.amazonaws.com/prod"

@marshallbunch

This comment has been minimized.

Copy link

marshallbunch commented Jul 20, 2017

did that as well.

@jayair

This comment has been minimized.

Copy link
Member

jayair commented Jul 20, 2017

@marshallbunch Can you show me the full command you used as well? I'm not too familiar with the shell in Windows but let's take a look.

@manubhat90 Good catch. It would work either way but that can be confusing.

@marshallbunch

This comment has been minimized.

Copy link

marshallbunch commented Jul 20, 2017

@jayair It is most definitely a syntax problem for the shell in windows. I got past the "invalid UserPoolId" error by getting rid of all the \ and the = and '. The current error is that it doens't like the json in the body content.

apig-test --username admin@example.com --password Passw0rd! --user-pool-id us-east-1_HwIVtcRh2 --app-client-id 34bb7b87t6rtc387foiletrldf --cognito-region us-east-1 --identity-pool-id us-east-1:285f61b7-8a95-4596-90ce-7f7e1848c2ed --invoke-url https://6xosj8ww6h.execute-api.us-east-1.amazonaws.com/prod/words --api-gateway-region us-east-1' --path-template /words' --method POST --body {"content":"hello world","attachment":"hello.jpg"}
Authenticating with User Pool
Getting temporary credentials
Making API request
C:\Users\proet\AppData\Roaming\npm\node_modules\aws-api-gateway-cli-test\node_modules\aws-sdk\lib\request.js:31
            throw err;
            ^

SyntaxError: Unexpected token c in JSON at position 1
    at JSON.parse (<anonymous>)
    at makeRequest (C:\Users\proet\AppData\Roaming\npm\node_modules\aws-api-gateway-cli-test\index.js:131:19)
    at C:\Users\proet\AppData\Roaming\npm\node_modules\aws-api-gateway-cli-test\index.js:114:5
    at C:\Users\proet\AppData\Roaming\npm\node_modules\aws-api-gateway-cli-test\node_modules\aws-sdk\lib\credentials.js:123:23
    at Response.<anonymous> (C:\Users\proet\AppData\Roaming\npm\node_modules\aws-api-gateway-cli-test\node_modules\aws-sdk\lib\credentials\cognito_identity_credentials.js:258:7)
    at Request.<anonymous> (C:\Users\proet\AppData\Roaming\npm\node_modules\aws-api-gateway-cli-test\node_modules\aws-sdk\lib\request.js:364:18)
    at Request.callListeners (C:\Users\proet\AppData\Roaming\npm\node_modules\aws-api-gateway-cli-test\node_modules\aws-sdk\lib\sequential_executor.js:105:20)
    at Request.emit (C:\Users\proet\AppData\Roaming\npm\node_modules\aws-api-gateway-cli-test\node_modules\aws-sdk\lib\sequential_executor.js:77:10)
    at Request.emit (C:\Users\proet\AppData\Roaming\npm\node_modules\aws-api-gateway-cli-test\node_modules\aws-sdk\lib\request.js:683:14)
    at Request.transition (C:\Users\proet\AppData\Roaming\npm\node_modules\aws-api-gateway-cli-test\node_modules\aws-sdk\lib\request.js:22:10)
@jayair

This comment has been minimized.

Copy link
Member

jayair commented Jul 20, 2017

@marshallbunch Yeah I think we need to figure out how to format a string as an argument in the command line. And possibly escape the characters properly.

@tsdorsey

This comment has been minimized.

Copy link

tsdorsey commented Jul 21, 2017

Hey guys. Great walkthrough. Everything went smoothly until it was time to test the API. I'm getting 502 bad gateway back from API Gateway. I looked in the CloudWatch logs and found that it can't import modules.

Unable to import module 'create': Error
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/var/task/create.js:76:18)
at __webpack_require__ (/var/task/create.js:20:30)
at Object.<anonymous> (/var/task/create.js:171:20)

I dug into this more by running the get lambda from the API gateway console dashboard using the test command. I got this:

Endpoint response body before transformations: 
{
  "errorMessage": "Cannot find module 'babel-runtime/regenerator'",
  "errorType": "Error",
  "stackTrace": [
    "require (internal/module.js:20:19)", 
    "Object.<anonymous> (/var/task/list.js:76:18)", 
    "__webpack_require__ (/var/task/list.js:20:30)", 
    "Object.<anonymous> (/var/task/list.js:176:20)", 
    "__webpack_require__ (/var/task/list.js:20:30)", 
    "/var/task/list.js:63:18", 
    "Object.<anonymous> (/var/task/list.js:66:10)"
  ]
}

This led me to look into the file being uploaded to S3 by serverless deploy and found that they didn't include webpack. I've attached a screenshot of the unzipped file sent to S3 and the files built by using serverless webpack. As you can see, the node_modules folder is very different between them.

screenshot 2017-07-21 15 41 29

Some of the results of serverless deploy:

$ serverless deploy
Serverless: Bundling with Webpack...
Time: 1698ms
     Asset     Size  Chunks             Chunk Names
 create.js  7.54 kB       0  [emitted]  create
 update.js  7.41 kB       1  [emitted]  update
   list.js  7.11 kB       2  [emitted]  list
    get.js  7.06 kB       3  [emitted]  get
 delete.js  6.84 kB       4  [emitted]  delete
handler.js  3.35 kB       5  [emitted]  handler
   [0] external "babel-runtime/core-js/json/stringify" 42 bytes {0} {1} {2} {3} {4} {5} [not cacheable]
   [1] external "babel-runtime/regenerator" 42 bytes {0} {1} {2} {3} {4} [not cacheable]
   [2] external "babel-runtime/helpers/asyncToGenerator" 42 bytes {0} {1} {2} {3} {4} [not cacheable]
   [3] ./lib/dynamodb-lib.js 652 bytes {0} {1} {2} {3} {4} [built]
   [4] external "aws-sdk" 42 bytes {0} {1} {2} {3} {4} [not cacheable]
   [5] ./lib/response-lib.js 721 bytes {0} {1} {2} {3} {4} [built]
   [6] ./create.js 2.99 kB {0} [built]
   [7] external "uuid" 42 bytes {0} [not cacheable]
   [8] ./delete.js 2.37 kB {4} [built]
   [9] ./get.js 2.58 kB {3} [built]
  [10] ./handler.js 696 bytes {5} [built]
  [11] ./list.js 2.61 kB {2} [built]
  [12] ./update.js 2.9 kB {1} [built]
Serverless: Packing external modules: babel-runtime@6.23.0, uuid@3.1.0
Serverless: Packaging service...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service .zip file to S3 (14.28 KB)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
......................................
Serverless: Stack update finished...
Service Information
service: notes-app-api
stage: prod
region: us-west-2
api keys:
  None
endpoints:
  ---
functions:
  create: notes-app-api-prod-create
  list: notes-app-api-prod-list
  get: notes-app-api-prod-get
  update: notes-app-api-prod-update
  delete: notes-app-api-prod-delete

Any help would be very much appreciated.

@jayair

This comment has been minimized.

Copy link
Member

jayair commented Jul 21, 2017

@tsdorsey Thanks for the details. As a quick sanity check, can I see your package.json and serverless.yml?

@tsdorsey

This comment has been minimized.

Copy link

tsdorsey commented Jul 22, 2017

@jayair I should have done this before I posted.
https://github.com/tsdorsey/sls-notes-app

I have serverless-dynamodb-local and serverless-offline in my package file but I'm not using them at the moment. I planned to do that later.

@marshallbunch

This comment has been minimized.

Copy link

marshallbunch commented Jul 22, 2017

@tsdorsey Good catch. It appears I'm experiencing the same issue.

@tsdorsey

This comment has been minimized.

Copy link

tsdorsey commented Jul 22, 2017

@marshallbunch and @jayair I'm newish to webpack. Do you think you could point me in a direction so I could try to help figure this out? Got any gut feelings?

@tsdorsey

This comment has been minimized.

Copy link

tsdorsey commented Jul 22, 2017

Ok, so I watched the folders as I ran serverless package and the .webpack folder is created with the dependencies in the node_modules folder as expected. Then the zip file is made and the .webpack folder is cleaned up. I have been reading through the package plugin; I'm suspect of the excludes directive but the aren't logged... :(

@navinkumarr

This comment has been minimized.

Copy link

navinkumarr commented Jul 22, 2017

Getting 403 response

Authenticating with User Pool
Getting temporary credentials
Making API request
{ status: 403,
  statusText: 'Forbidden',
  data: { message: 'Forbidden' } }
@Jonarod

This comment has been minimized.

Copy link

Jonarod commented Jul 22, 2017

Yeah I get the same response...

{ status: 403,
  statusText: 'Forbidden',
  data: { Message: 'User: arn:aws:sts::907468717626:assumed-role/Cognito_notesidentitypoolAuth_Role/CognitoIdentityCredentials is not authorized to perform: execute-api:Invoke on resource: arn:aws:execute-api:us-east-2:********7626:ux5xagukr9/prod/POST/notes' } }

I guess we forgot some tweaks that are not in the code, but rather in the aws console.

@Jonarod

This comment has been minimized.

Copy link

Jonarod commented Jul 22, 2017

Ok, I got it working.
Basically, I deleted my Federated Identity Pool and recreated it from scratch following this section:

http://serverless-stack.com/chapters/create-a-cognito-identity-pool.html

Note that after doing so, I got these messes:

  • My Authenticated rule was already existing, so AWS would not let me change it. To change it, you have to head over your IAM service, within the "Roles" section. Here, look for your existing rule and edit it to be like in the tutorial.
  • My Authenticated rule was still restricting to old Federated Identity Pool. You can fix that in the "Trust Relationships" tab of the same "Roles" section of the IAM service. You should press "Edit relationships" and replace your old Identity pool ID with the new one.

After that, I got correct 200 status.

Hope it helps

@mikhael28

This comment has been minimized.

Copy link

mikhael28 commented Jul 22, 2017

I'm not able to clear this test - if I put in all of my information in as a string, I get the cmd line response:
'Authenticating with User Pool
User does not exist'

Which makes no sense, because the user definitely exists - I created one with the same default credentials as in the example and a seperate one, which I used to create, update, delete the event.json file throughout the tutorial.

When I remove all the semi-colons from the data, it runs through saying:
'Authenticating with User Pool'
Getting temporary credential
Making API request

And then gives me the same JSON token error as the other commenter upstairs!

When I try just taking the string out the username and password, and keeping the rest of the strings there (and some variations) I get this error message:
Authenticating with UserPool
Getting temporary credentials
Inaccessible host: cognito-identity.xn--us-east-2-499dua.amazonaws.com'. This service may not be available in the ‘us-east-2’' region.

However, from looking at AWS documentation, Cognito Identity should be available in US-East-2... Halp!

@jayair

This comment has been minimized.

Copy link
Member

jayair commented Jul 22, 2017

@tsdorsey I just tried your repo and I got it to deploy and call it fine. Of course the call failed because I don't have the IAM roles set up properly to do this. But It's calling everything fine.

screen shot 2017-07-22 at 3 03 29 pm

screen shot 2017-07-22 at 3 04 29 pm

I suspect there is something going on on your local. Can you try the following and check the versions you are running?

screen shot 2017-07-22 at 3 05 42 pm

@jayair

This comment has been minimized.

Copy link
Member

jayair commented Jul 22, 2017

@marshallbunch Are you seeing the same error as @tsdorsey? If you go into your CloudWatch logs do you see the same error (Unable to import module 'create': Error)?

@jayair

This comment has been minimized.

Copy link
Member

jayair commented Jul 22, 2017

@Jonarod Yeah that error sounds like the IAM Role was not set properly. Thanks for reporting back with detail. I'm sure it'll help folks that run into something similar.

@jayair

This comment has been minimized.

Copy link
Member

jayair commented Jul 22, 2017

@navinkumarr Your issue sounds like the issue @Jonarod ran into. You can check if the IAM Role has been set properly by going to your AWS Console > IAM > Roles (in the sidebar) > Cognito_notesidentitypoolAuth_Role > Scroll down and click on Show Policy.

screen shot 2017-07-22 at 3 14 54 pm

And make sure the policy looks like the one in the tutorial.

@jayair

This comment has been minimized.

Copy link
Member

jayair commented Jul 22, 2017

@mikhaelbendavid Are you on Windows as well like @marshallbunch? Can I see the full command you used that generated that last error?

@thesavvygreek

This comment has been minimized.

Copy link

thesavvygreek commented Jul 22, 2017

@jayair I'm getting

{ status: 502,
  statusText: 'Bad Gateway',
  data: { message: 'Internal server error' } }

Digging deeper into Cloudwatch, specifically the create lambda function, I get

Unable to import module 'create': Error
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/var/task/create.js:76:18)
at __webpack_require__ (/var/task/create.js:20:30)
at Object.<anonymous> (/var/task/create.js:167:20)
at __webpack_require__ (/var/task/create.js:20:30)
at /var/task/create.js:63:18
at Object.<anonymous> (/var/task/create.js:66:10)

My package.json is:

{
  "name": "notes-app-api",
  "version": "1.0.0",
  "description": "",
  "main": "handler.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-core": "^6.25.0",
    "babel-loader": "^7.1.1",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-stage-3": "^6.24.1",
    "glob": "^7.1.2",
    "serverless-webpack": "^2.0.0",
    "webpack": "^3.3.0",
    "webpack-node-externals": "^1.6.0"
  },
  "dependencies": {
    "babel-runtime": "^6.23.0"
  }
}

I haven't done any digging into the packaging that serverless deploy produces but this is to confirm I'm experiencing the same issue as @tsdorsey is experiencing.

@jayair

This comment has been minimized.

Copy link
Member

jayair commented Jul 22, 2017

@thesavvygreek Can I see what version of Node, NPM, and Serverless you are using?

@jayair

This comment has been minimized.

Copy link
Member

jayair commented Apr 4, 2018

@viccooper142 Thanks for reporting back!

@Tee88

This comment has been minimized.

Copy link

Tee88 commented Apr 11, 2018

How does the APIclass in Amplify pass similar info as in the apig-test below? How does my API know whether the cognito user who invoked the API belongs to identity pool in which I attached :

{
      "Effect": "Allow",
      "Action": [
        "execute-api:Invoke"
      ],
      "Resource": [
        "arn:aws:execute-api:YOUR_API_GATEWAY_REGION:*:YOUR_API_GATEWAY_ID/*"
      ]
    }
apig-test \
--username='admin@example.com' \
--password='Passw0rd!' \
--user-pool-id='us-east-1_YBhdXYvix' \
--app-client-id='29qwoeorti0ctjkur5h91lkw5g' \
--cognito-region='us-east-1' \
--identity-pool-id='us-east-1:565cc505-5486-4278-bf0f-9736p9apq8m5' \
--invoke-url='https://w5z1hluqmp5.execute-api.us-east-1.amazonaws.com/test' \
--api-gateway-region='us-east-1' \
--path-template='/notes' \
--method='POST' \
--body='{"content":"hello world","attachment":"hello.jpg"}'
@jayair

This comment has been minimized.

Copy link
Member

jayair commented Apr 11, 2018

@Tee88 Amplify handles your app as a whole. When you first configure Amplify we set all the Cognito info, similar to what we do for apig-test - https://github.com/AnomalyInnovations/serverless-stack-demo-client/blob/master/src/config.js

So it knows that you are using those credentials to access the API.

@willieray25

This comment has been minimized.

Copy link

willieray25 commented Apr 13, 2018

Greetings. Having an issue currently. From what i can gather it may be babel related, though i have followed the instructions exactly, and have not had any errors up until now that were easily fixed typos.

Getting the 502 error:

Authenticating with User Pool
Getting temporary credentials
Making API request
{ status: 502,
  statusText: 'Bad Gateway',
  data: { message: 'Internal server error' } }

Cloudwatch output:
Syntax error in module 'create': SyntaxError async function main(event, context, callback) { ^^^^^^^^ SyntaxError: Unexpected token function at createScript (vm.js:56:10) at Object.runInThisContext (vm.js:97:10) at Module._compile (module.js:542:28) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.require (module.js:497:17) at require (internal/module.js:20:19)

Appreciate the help. This body of work is incredible.
BB

EDIT
Changing my Lambda function runtime to Node 8.10 in the AWS Console eliminated the error. I would still like to better understand the issue, but i can move forward

EDIT AGAIN
Looks like I was bitten by an upstream change. The commit from 1.5 days ago added support for Node8.10. I just happen to be working through it when it happened. Please disregard. I've rebuilt all files.

@jayair

This comment has been minimized.

Copy link
Member

jayair commented Apr 16, 2018

@willieray25 Yeah there was a recent update that can cause this. Glad you figure it out.

@thevamad

This comment has been minimized.

Copy link

thevamad commented Apr 30, 2018

@jayair : I'm not able to get past the following error. My .aws/credentials file has the access key and secret key and the region is hard coded into the dynamo-lib file. Do you happen to know what could cause this ? The region on all my js files / user pools / etc are all 'us-west-2' ...

{ 
  status: 403,
  statusText: 'Forbidden',
  data: { message: 'Credential should be scoped to a valid region, not \'us-east-1\'. ' } 
}
@jayair

This comment has been minimized.

Copy link
Member

jayair commented Apr 30, 2018

@thevamad This usually happens when the region used to sign the requests doesn't match the endpoint. Can I see the full command that is causing this error?

@thevamad

This comment has been minimized.

Copy link

thevamad commented Apr 30, 2018

I'm running this on a windows machine and had to do an additional step to set up serverless config params (for some reason aws configure was working to run CLI commands but not working with the serverless code)..

npx aws-api-gateway-cli-test --username madhu@gmail.com --p
assword Password_1 --user-pool-id us-west-2_KkiPPu5xj --app-client-id ohorcp7n9q
tap2jqbrmnof789 --cognito-region us-west-2 --identity-pool-id us-west-2:e5f17dcd
-2650-4f22-a3e4-d19531195986 --invoke-url https://q350s3y4r3.execute-api.us-west
-2.amazonaws.com/prod/notes --api-gateway -region us-west-2 --path-template note
s --method POST --body "{""content"":""helloworld"",""attachment"":""hello.jpg""
}"
@jayair

This comment has been minimized.

Copy link
Member

jayair commented Apr 30, 2018

@thevamad I'm not sure if this is a typo --api-gateway -region but just make sure the region is set correctly.

@thevamad

This comment has been minimized.

Copy link

thevamad commented Apr 30, 2018

Oh man. You're right. That was a typo :) Thanks a ton!

@jonasbarsten

This comment has been minimized.

Copy link

jonasbarsten commented May 2, 2018

This solved my 403:

IAM -> Roles -> Cognito_notesAuth_Role -> oneClick_Cognito_notesAuth_Role_XXXXXXXXX -> Edit Policy -> JSON:

On line 30, the copy/paste of the code from the tutorial had beed "auto-corrected" from "arn", to "Arn".

It should be lowercase.

@jayair

This comment has been minimized.

Copy link
Member

jayair commented May 2, 2018

@jonasbarsten Oh wow, that is a really annoying problem caused by auto-correct.

@jonasbarsten

This comment has been minimized.

Copy link

jonasbarsten commented May 2, 2018

@jayair Not as annoying as the world was before you made this tutorial ;)

@ahammond

This comment has been minimized.

Copy link

ahammond commented May 2, 2018

I'm getting

 ~/notes-app-api   master   scripts/aws-api-gateway-cli-test.sh
npx: installed 103 in 5.486s
Authenticating with User Pool
Getting temporary credentials
Making API request
{ status: 500,
  statusText: 'Internal Server Error',
  data: { status: false } }

When I run the test. I've added console.log(e) to all the handlers, but don't get any additional information. Where should I look to find my mistake? https://github.com/ahammond/notes-app-api is my WIP.

Hmm. serverless --aws-profile personal logs -f create gives me

START RequestId: 220ccc23-4e59-11e8-ac2d-1f262356d857 Version: $LATEST
2018-05-02 15:35:37.700 (-07:00)	220ccc23-4e59-11e8-ac2d-1f262356d857	{ CredentialsError: Missing credentials in config
    at Object.fs.openSync (fs.js:646:18)
    at Object.fs.readFileSync (fs.js:551:33)
    at Object.readFileSync (/var/runtime/node_modules/aws-sdk/lib/util.js:97:26)
    at SharedIniFile.loadFile [as ensureFileLoaded] (/var/runtime/node_modules/aws-sdk/lib/shared_ini.js:19:18)
    at SharedIniFile.loadProfileNames [as getProfiles] (/var/runtime/node_modules/aws-sdk/lib/shared_ini.js:61:10)
    at SharedIniFileCredentials.refresh (/var/runtime/node_modules/aws-sdk/lib/credentials/shared_ini_file_credentials.js:94:45)
    at SharedIniFileCredentials.get (/var/runtime/node_modules/aws-sdk/lib/credentials.js:121:12)
    at getAsyncCredentials (/var/runtime/node_modules/aws-sdk/lib/config.js:332:24)
    at Config.getCredentials (/var/runtime/node_modules/aws-sdk/lib/config.js:352:9)
    at Request.VALIDATE_CREDENTIALS (/var/runtime/node_modules/aws-sdk/lib/event_listeners.js:80:26)
  message: 'Missing credentials in config',
  errno: -2,
  code: 'CredentialsError',
  syscall: 'open',
  path: '/home/sbx_user1059/.aws/credentials',
  time: 2018-05-02T22:35:37.692Z,
  originalError:
   { message: 'Could not load credentials from SharedIniFileCredentials',
     errno: -2,
     code: 'CredentialsError',
     syscall: 'open',
     path: '/home/sbx_user1059/.aws/credentials',
     time: 2018-05-02T22:35:37.692Z,
     originalError:
      { errno: -2,
        code: 'ENOENT',
        syscall: 'open',
        path: '/home/sbx_user1059/.aws/credentials',
        message: 'ENOENT: no such file or directory, open \'/home/sbx_user1059/.aws/credentials\'' } } }
END RequestId: 220ccc23-4e59-11e8-ac2d-1f262356d857
REPORT RequestId: 220ccc23-4e59-11e8-ac2d-1f262356d857	Duration: 37.66 ms	Billed Duration: 100 ms 	Memory Size: 1024 MB	Max Memory Used: 63 MB

I have multiple aws profiles. Related?

@thevamad

This comment has been minimized.

Copy link

thevamad commented May 3, 2018

@ahammond : I had the same issue. I used this command to configure the serverless credentials per the following link. I had previously set this up using aws configure which only seemed to use the credentials on any CLI command that was run.
https://serverless.com/framework/docs/providers/aws/guide/credentials/

serverless config credentials --provider aws --key AKIAIOSFODNN7EXAMPLE --secret wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

@ahammond

This comment has been minimized.

Copy link

ahammond commented May 3, 2018

@thevamad I tried that (clobbered my default profile with my personal profile) and am still getting the same error.

@jayair

This comment has been minimized.

Copy link
Member

jayair commented May 3, 2018

@ahammond Are you setting which profile to use in your Lambda function?

@thevamad

This comment has been minimized.

Copy link

thevamad commented May 3, 2018

@ahammond : the other thing that worked for me is setting credentials in the lambda like so

AWS.Config.update ( {accessKeyId: 'AKID', 
secretAccessKey: 'SECRET', 
region: 'us-west-2'});
@devsteff

This comment has been minimized.

Copy link

devsteff commented May 7, 2018

I also received a 403 - Forbidden access.

After doublechecking erverything, it turns out, that the cut'n'paste of the Access Rule from the PDF was the problem. The hyphen characters from the longer lines are not copied and so the keywords are rubbish. You can try it by yourself. Just copy the snippet from the PDF and insert it into your editor.

"Resource": [
"arn:aws:s3:::YOUR_S3_UPLOADS_BUCKET_NAME/private/${cognitoidentity.
amazonaws.com:sub}/*"
:
:

must be
"Resource": [
"arn:aws:s3:::YOUR_S3_UPLOADS_BUCKET_NAME/private/${cognito-identity.
amazonaws.com:sub}/*"
:
:

and as well
"Resource": [
"arn:aws:executeapi:
YOUR_API_GATEWAY_REGION::YOUR_API_GATEWAY_ID/"
]

must be
"Resource": [
"arn:aws:execute-api:
YOUR_API_GATEWAY_REGION::YOUR_API_GATEWAY_ID/"
]

I'm not sure if it is a mac specific copy'n'paste issue, but it takes me hours to figure out whats going wrong. Maybe this hint is helpful ....

@jayair

This comment has been minimized.

Copy link
Member

jayair commented May 7, 2018

@devsteff Hmmm that's weird. I just tried the exact same lines from the PDF and it worked okay for me. I'm on macOS 10.13. Are the hyphens missing only for these snippets?

@devsteff

This comment has been minimized.

Copy link

devsteff commented May 7, 2018

Yes, Seems so. I figured out, that when using the Apple Preview App for the PDF, copy'n'paste is ok. The hyphen is there, but line ist splittet and must be joined. But with Adobe Acrobat Reader App (Architecture: x86_64, Build: 18.11.20038.267465, AGM: 4.30.74, CoolType: 5.14.5, JP2K: 1.2.2.39492)
you can reproduce the issue. So I think it's more a Adobe twist, than a problem in the PDF.

@jayair

This comment has been minimized.

Copy link
Member

jayair commented May 9, 2018

@devsteff I see. Thanks for letting us know. I'll add a note in there.

@jayair jayair closed this May 9, 2018

@jayair jayair reopened this May 9, 2018

@jayair

This comment has been minimized.

Copy link
Member

jayair commented May 9, 2018

@jayair jayair closed this May 9, 2018

@jayair

This comment has been minimized.

Copy link
Member

jayair commented Jun 13, 2018

@Ashraf-Younis-NM Can you post this here - https://discourse.serverless-stack.com/t/comments-test-the-apis/122? We are moving any discussions around the chapters to Discourse.

@KatieChen1001

This comment has been minimized.

Copy link

KatieChen1001 commented Jun 19, 2018

@jayair I'm running into the same problem as @mikhaelbendavid with error message. Checked all configurations all same as the tutorial. I was wondering what could be the problem? Many thanks!

@jayair

This comment has been minimized.

Copy link
Member

jayair commented Jun 21, 2018

@KatieChen1001 I replied in the Discourse thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment