Test the Configured APIs

More on this

{
  "errorMessage": "Unexpected token u in JSON at position 0",
  "errorType": "SyntaxError",
  "stackTrace": [
    "JSON.parse (<anonymous>)",
    "_callee$ (/var/task/webpack:/create.js:6:21)",
    "tryCatch (/var/task/node_modules/regenerator-runtime/runtime.js:62:40)",
    "Generator.invoke [as _invoke] (/var/task/node_modules/regenerator-runtime/runtime.js:296:22)",
    "Generator.prototype.(anonymous function) [as next] (/var/task/node_modules/regenerator-runtime/runtime.js:114:21)",
    "step (/var/task/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)",
    "/var/task/node_modules/babel-runtime/helpers/asyncToGenerator.js:35:14",
    "new Promise (<anonymous>)",
    "new F (/var/task/node_modules/core-js/library/modules/_export.js:36:28)",
    "/var/task/node_modules/babel-runtime/helpers/asyncToGenerator.js:14:12"
  ]
}

Never mind its resolved!

Oh what was the issue?

Hi jayair,

I’m getting a 500 trying to test the API. Could you give me suggestions as to how to go about debugging the error? Thanks vm!

— below is my test run after creating a test user

    bash-3.2$ npx aws-api-gateway-cli-test \
    --username='admin@example.com' \
    --password='Passw0rd!' \
    --user-pool-id='us-east-2_ftYJN6YTE' \
    --app-client-id='2etl65d6u2p5lsjrn1u9cmhkh1' \
    --cognito-region='us-east-2' \
    --identity-pool-id='us-east-2:9c7bbdf6-ebf7-4f68-8408-b17cec95e759' \
    --invoke-url='https://cq6qo7q5n7.execute-api.us-east-2.amazonaws.com/dev' \
    --api-gateway-region='us-east-2' \
    --path-template='/notes' \
    --method='POST' \
    --body='{"content":"hello-dev0-world","attachment":"hello.jpg"}'
    npx: installed 103 in 3.243s
    Authenticating with User Pool
    Getting temporary credentials
    Making API request
    { status: 500,
      statusText: 'Internal Server Error',
      data: { status: false } }
    bash-3.2$ 

– below is the end of the build log

Stack Outputs
AttachmentsBucketName: sls-api-dev-attachmentsbucket-1d6ippxpi7ewy
UserPoolClientId: 2etl65d6u2p5lsjrn1u9cmhkh1
UserPoolId: us-east-2_ftYJN6YTE
DeleteLambdaFunctionQualifiedArn: arn:aws:lambda:us-east-2:868242285281:function:sls-api-dev-delete:2
CreateLambdaFunctionQualifiedArn: arn:aws:lambda:us-east-2:868242285281:function:sls-api-dev-create:2
GetLambdaFunctionQualifiedArn: arn:aws:lambda:us-east-2:868242285281:function:sls-api-dev-get:2
UpdateLambdaFunctionQualifiedArn: arn:aws:lambda:us-east-2:868242285281:function:sls-api-dev-update:2
IdentityPoolId: us-east-2:9c7bbdf6-ebf7-4f68-8408-b17cec95e759
BillingLambdaFunctionQualifiedArn: arn:aws:lambda:us-east-2:868242285281:function:sls-api-dev-billing:1
ListLambdaFunctionQualifiedArn: arn:aws:lambda:us-east-2:868242285281:function:sls-api-dev-list:2
ServiceEndpoint: https://cq6qo7q5n7.execute-api.us-east-2.amazonaws.com/dev
ServerlessDeploymentBucketName: sls-api-dev-serverlessdeploymentbucket-1fvqmcj3wd4ef

====================
🗑 Cleanup
====================

2018/07/12 21:32:48 Post deploy cleanup

✅ Build v1 successfully deployed!

For 500 errors, it is most likely coming from your Lambda functions. You can add a console.log and check the logs in Seed to debug the issue. We cover how to check the logs in this chapter:

Thanks Jay!

The lambda function never gets a chance to be executed no matter how many console.log lines I add to the code. It 500s before getting to the code as far as I can tell.

I think the cause is the hard-coded “us-east-1” in the libs/ sub dir:

All my stuff lives in Ohio, us-east-2.

I suspect anyone whose region is different from what’s in that libs file will run into the same problem I have.

1 Like

Ah yeah. That is on our todo to remove that line. You shouldn’t need that since we are setting the region through the serverless.yml.

Hi
I am getting a Forbidden error and can’t seem to trace its origin.

    npx: installed 105 in 14.884s
Authenticating with User Pool
Getting temporary credentials
Making API request
{ status: 403,
  statusText: 'Forbidden',
  data: 
   { message: 'Credential should be scoped to a valid region, not \'us-east-1\'. ' } }

I am using ‘eu-west-1’ and have changed it within the code.

I’m not sure if this is related but we used to have the us-east-1 hardcoded in the dynamodb-lib.js. We updated the tutorial recently but you might still have that in there.

We were talking about it above:

I’m having the same problem after I implemented the new deployment methods for the deployment automation.
I’ve changed the lib back when it all worked but it keeps getting me the same error.
Any help? Is there something I can edit?

What’s the error you are having again?

When trying to run the aws-api-gateway-cli-test command, I get the following error:

Authenticating with User Pool
Getting temporary credentials
Making API request
/usr/local/lib/node_modules/aws-api-gateway-cli-test/node_modules/aws-sdk/lib/request.js:31
throw err;
^

TypeError: Cannot read property ‘1’ of null
at Object.apigClientFactory.newClient (/usr/local/lib/node_modules/aws-api-gateway-cli-test/node_modules/aws-api-gateway-client/dist/apigClient.js:63:57)
at makeRequest (/usr/local/lib/node_modules/aws-api-gateway-cli-test/index.js:157:38)
at /usr/local/lib/node_modules/aws-api-gateway-cli-test/index.js:150:5
at /usr/local/lib/node_modules/aws-api-gateway-cli-test/node_modules/aws-sdk/lib/credentials.js:123:23
at Response. (/usr/local/lib/node_modules/aws-api-gateway-cli-test/node_modules/aws-sdk/lib/credentials/cognito_identity_credentials.js:258:7)
at Request. (/usr/local/lib/node_modules/aws-api-gateway-cli-test/node_modules/aws-sdk/lib/request.js:364:18)
at Request.callListeners (/usr/local/lib/node_modules/aws-api-gateway-cli-test/node_modules/aws-sdk/lib/sequential_executor.js:109:20)
at Request.emit (/usr/local/lib/node_modules/aws-api-gateway-cli-test/node_modules/aws-sdk/lib/sequential_executor.js:81:10)
at Request.emit (/usr/local/lib/node_modules/aws-api-gateway-cli-test/node_modules/aws-sdk/lib/request.js:683:14)
at Request.transition (/usr/local/lib/node_modules/aws-api-gateway-cli-test/node_modules/aws-sdk/lib/request.js:22:10)

Can I see the full command you are running?

npx aws-api-gateway-cli-test \
  --username='admin@example.com' \
  --password='Passw0rd!' \
  --user-pool-id='us-east-1_TvDTXmJUy' \
  --app-client-id='6stng9a2077jii9o3j36bslb4l' \
  --cognito-region='us-east-1' \
  --identity-pool-id='us-east-1:a52ef563-b9a4-4d69-bc38-60f140987bf2' \
  --invoke-url='api.crisispaintball.com/dev' \
  --api-gateway-region='us-east-1' \
  --path-template='/notes' \
  --method='POST' \
  --body='{"content":"hello world","attachment":"hello.jpg"}'

I’m also getting the message: Error: Request failed with status code 500, when I build the React app for dev, run it locally, and try to do anything in the Notes app that requires an API call (ie. create a new note).

I’m not sure where the best place to post this issue would be, so if you point me in the right direction I can move this comment.

I resolved my status code 500 issue by making the changes found here:

1 Like

Oh I’m glad that helped you out!

I am get a 403 error when I try to test the api-gateway.

$ npx aws-api-gateway-cli-test
–username=‘admin@example.com’
–password=‘Passw0rd!’
–user-pool-id=‘us-east-1_8uPZvWNTi’
–app-client-id=‘176k27ktpjb7b4md1s1rifneei’
–cognito-region=‘us-east-1’
–identity-pool-id=‘us-east-1:9c80f142-cb02-40ed-9b49-593104e4158d’
–invoke-url=“https://uqlien7vub.execute-api.us-east-1.amazonaws.com/dev
–api-gateway-region=‘us-east-1’
–path-template=‘/notes’
–method=‘POST’
–body=‘{“content”:“hello world”,“attachment”:“hello.jpg”}’

npx: installed 105 in 33.656s
Authenticating with User Pool
Getting temporary credentials
Making API request
{ status: 403,
statusText: ‘Forbidden’,
data: { message: ‘Forbidden’ } }

I just started with Part II of the App and got to this part and can not get it to work. I have enabled logs and nothing shows up in any cloudwatch logs. I tested the api in the policy simulator and that worked. and Seed does not show any messages when I enable the logs.
Any suggestions on other things to test?

thanks,
bill

This is for anyone that may be using a Windows 10 system and having problems with 403 errors…

After many hours of testing, checking, etc and finally making a minor edit to apig-test to dump the entire “response” from the API Request when there is an error, I finally got this to work.
I am not 100% sure WHY it works, but it is probably Windows 10 and the shell I am using…

To start, I had all kinds of problems getting either the Command shell or powershell on windows 10 to accept all the parameters. I tried many attempts to escape the quotes and never got the command to work.
So I used Git Bash. It was easy to edit the line in notepad then paste into git bash and the command executed.

However, I was getting the 403 error. I double checked all the roles, policies, etc and they were correct.

So when I got apig-test to display the entire response message I found something strange…
in the headers that was sent to AWS is

POST /dev/C:/Program%20Files/Git/notes HTTP/1.1…

Where is the “C:/Program%20Files/Git/” coming from??? It is not in the command line.
To make an already long story shorter…
I fixed the problem by making a very simple change to the command line…

Before

–invoke-url=“https://uqlien7vub.execute-api.us-east-1.amazonaws.com/dev”
–path-template=’/notes’

After these simple edits to the URL to add trailing / and to path-template to remove leading /

–invoke-url=“https://uqlien7vub.execute-api.us-east-1.amazonaws.com/dev/”
–path-template=’notes’

IT WORKED!!! ??? !!!

If someone can explain this, I would love to know…
In the mean time, I am pressing on with this awesome tutorial.
Hopefully someone finds this helpful.

6 Likes

That’s really weird. Not sure what is going on there. But thanks for the detailed write-up. I’m sure it’ll help other Windows users.

1 Like