Test the Configured APIs


#21

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)


#22

Can I see the full command you are running?


#23
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"}'

#24

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.


#25

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


#26

Oh I’m glad that helped you out!


#27

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


#28

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.


#29

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.


#30

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.

#31

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.


#32

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