Test the Configured APIs

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.

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

I have run the following npx command on dev:

npx aws-api-gateway-cli-test \
--username='admin@example.com' \
--password='Passw0rd!' \
--user-pool-id='us-east-1_fZ3XofyFi' \
--app-client-id='2embh2inkauuieqtbll9uisk62' \
--cognito-region=‘us-east-1’ \
--identity-pool-id='us-east-1:2a9a76ff-e661-4ed2-b1a1-17434326dfa3' \
--invoke-url='https://2bbhwgva13.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"}'

…and get the following error:

npx: installed 105 in 4.695s
Authenticating with User Pool
Getting temporary credentials
Inaccessible host: `cognito-identity.xn--us-east-1-499dua.amazonaws.com'. This service may not be available in the `‘us-east-1’' region.

Update: I had copied and pasted the command from the tutorial instructions, and for some reason the apostrophes around the ‘us-east-1’ were different than all the other normal apostrophes. I fixed them, and now it works.

1 Like

Thanks for reporting back. Yeah the copy-paste from the PDF is not great. Try using the web version if you can.

I’m stuck on a 500 error… can anyone help?

Here’s the error logged in Seed for my /create lambda:

It looks It like the table name attempting to be updated is “notes,” where it should be “dev-notes.”

When I tested with the tableName hard-coded in the serverless.yml, it worked fine… solved my own problem, guys. I’d skimmed over the part in the tutorial about replacing the tableName variable under the environment block. Doh! Leaving this post here, in case anyone else runs into the same issue.

2 Likes

Glad you figured it out. Thanks for reporting back.

Windows users testing the API: Especially if using VS Code or Powershell
VS Code uses powershell, and it doesn’t seem to like the JSON in the body section

Use a normal windows command prompt when testing the API: run as admin
And use this syntax. This should work with no problems as long as all your CORS settings are correct: This is for both dev and prod, so update the script accordingly, with your credentials

npx aws-api-gateway-cli-test --username admin@example.com --password Passw0rd! --user-pool-id us-east-1_xxxxxxxxx --app-client-id xxxxxxxxxxxxxxxxxxxxxxxxx --cognito-region us-east-1 --identity-pool-id us-east-1:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --invoke-url https://xxxxxxxxxx.execute-api.us-east-1.amazonaws.com/prod --api-gateway-region us-east-1 --path-template /notes --method POST --body "{\"content\":\"hello world\",\"attachment\":\"hello.jpg\"}"
1 Like

Thanks for posting this!

@bwsolutions thanks for your comments. I got a 403 response then tried moving the leading and trailing / as per your instructions and it was successful - returns 200 now. I am also using Git Bash on Windows 10.

You sir, are the true MVP. Thanks for this solution, worked like a charm.