Skip to content
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 · 333 comments
Closed

Comments: Test the APIs #112

jayair opened this issue Jul 19, 2017 · 333 comments

Comments

@jayair
Copy link
Contributor

jayair commented Jul 19, 2017

Link to chapter - http://serverless-stack.com/chapters/test-the-apis.html

@yashg5
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
Copy link
Contributor Author

jayair commented Jul 20, 2017

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

@marshallbunch
Copy link

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
Copy link
Contributor Author

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='[email protected]' \
--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
Copy link

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

@jayair
Copy link
Contributor Author

jayair commented Jul 20, 2017

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

@marshallbunch
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
Copy link

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
Copy link

did that as well.

@jayair
Copy link
Contributor Author

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
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 [email protected] --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
Copy link
Contributor Author

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
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: [email protected], [email protected]
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
Copy link
Contributor Author

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
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
Copy link

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

@tsdorsey
Copy link

@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
Copy link

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
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
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
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
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link

@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
Copy link
Contributor Author

jayair commented Jul 22, 2017

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

@thevamad
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
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
Copy link
Contributor Author

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
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
Copy link
Contributor Author

jayair commented May 9, 2018

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

@jayair jayair closed this as completed May 9, 2018
@jayair jayair reopened this May 9, 2018
@jayair
Copy link
Contributor Author

jayair commented May 9, 2018

@jayair jayair closed this as completed May 9, 2018
@jayair
Copy link
Contributor Author

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
Copy link

@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
Copy link
Contributor Author

jayair commented Jun 21, 2018

@KatieChen1001 I replied in the Discourse thread.

@labibhussain
Copy link

I keep getting the 403 error but I'm not sure why. I've tried all the debugging suggestions, and even tried changing the policies around in the IAM (which arent giving me any denied errors). Here is what I'm finding in my logs
`npx aws-api-gateway-cli-test \

--username='[email protected]'
--password='Passw0rd!'
--user-pool-id='us-east-2_95w6Kuh38'
--app-client-id='73shgtmv0jap1bem97iht8scqn'
--cognito-region='us-east-2'
--identity-pool-id='us-east-2:52d98313-948d-4cca-993a-feb52498bfc3'
--invoke-url='https://czojib8dpe.execute-api.us-east-2.amazonaws.com/prod'
--api-gateway-region='us-east-2'
--path-template=‘/todo’
--method='POST'
--body='{"content":"hello world","attachment":"hello.jpg"}'
npx: installed 106 in 4.168s
Authenticating with User Pool
Getting temporary credentials
Making API request
{ status: 403,
statusText: 'Forbidden',
data: { message: 'Forbidden' } } `

@47arathore
Copy link

Something that I came across while testing in Windows is

  1. I need to remove all the \ = and ".
  2. Get the complete string to be in one line
  3. Make sure that in invoke-url, you are only using the main path. Don't include the lambda path also. Mistakes happen.
  4. If you are using mobilehub, even if you will be using the same user pool, there will be different identity pool created for your app and a different app client in selected user pool clients. So, make sure the cognito-identity-pool-id belongs to that specific pool and the app client id is of your mobilehub.

NOTE. Most of the time the issue will be resolved by 1, 2, and 3 point. You only need to take care of mobilehub cognito identity pool id, if in your code you are using congintoIdentity from the event. As this will lead to some inconsistencies during testing, and you have to be more careful.

So, I successfully tested my command as given below
apig-test --username [email protected] --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 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='[email protected]' \
--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"}'

@christian-townsend
Copy link

Is this thread still being supported? I don't want to thoroughly describe my issue if no one is able to assist! Cheers.

@jayair
Copy link
Contributor Author

jayair commented Feb 8, 2020

Post over on the forums instead — https://discourse.serverless-stack.com

@mgonawala
Copy link

I am not sure if this thread is still maintained or not, but I just wanted to thank @bradodarb for his comment on solving 403 error. After following his advice I was able to solve error.
Solution: keep --path-template empty and append your path value to the Gateway URL itself.

And also, Thanks to @jayair for such an amazing tutorial. You really are helping every tech enthusiast in the best possible way. Cheers !

@jayair
Copy link
Contributor Author

jayair commented Mar 30, 2020

@mgonawala Thanks for kind words!

Yeah we've moved over to our forums for chapter related comments.

@SteveDenton
Copy link

I'm really stuck here, been at it 3 days so far. Here is the forum post: https://discourse.serverless-stack.com/t/debugging-api-gateway/2011/3 - posting here in case anyone can help?

@contactwajeeh
Copy link

I am on windows at stuck at this error, can anyone shed some light

{
  status: 400,
  statusText: 'Bad Request',
  data: '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\n' +
    '<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">\n' +
    '<TITLE>ERROR: The request could not be satisfied</TITLE>\n' +
    '</HEAD><BODY>\n' +
    '<H1>400 ERROR</H1>\n' +
    '<H2>The request could not be satisfied.</H2>\n' +
    '<HR noshade size="1px">\n' +
    'Bad request.\n' +
    "We can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner.\n" +
    '<BR clear="all">\n' +
    'If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.\n' +
    '<BR clear="all">\n' +
    '<HR noshade size="1px">\n' +
    '<PRE>\n' +
    'Generated by cloudfront (CloudFront)\n' +
    'Request ID: ioI1VugXiqUDpE2XOUpgzpdFqLqOmIMJiwEuGdStUzb4pTMbgDldOQ==\n' +
    '</PRE>\n' +
    '<ADDRESS>\n' +
    '</ADDRESS>\n' +
    '</BODY></HTML>'
}

@jayair
Copy link
Contributor Author

jayair commented Oct 15, 2020

Can you post this over on — https://discourse.serverless-stack.com/

@awahmed
Copy link

awahmed commented Oct 18, 2020

Hello everyone I am having a problem with testing the api. When I run all the other tests in mock, my backend is updated and I see what I created,updated,deleted,etc. But when I run the command(I'm omitting alot of details. 'body' is my main question here): npx aws-api-gateway-cli-test --api-gateway-region us-east-1 --path-template /requests --method POST --body "{\"content\":\"test req\",\"amount\":\"120\",\"attachment\":\"bye.jpg\"}"

its giving me this error:

Authenticating with User Pool
Getting temporary credentials
Making API request
undefined:1
{\
 ^

SyntaxError: Unexpected token \ in JSON at position 1
    at JSON.parse (<anonymous>)
    at makeRequest (C:\Users\aamai\AppData\Roaming\npm-cache\_npx\18348\node_modules\aws-api-gateway-cli-test\index.js:179:17)
    at C:\Users\aamai\AppData\Roaming\npm-cache\_npx\18348\node_modules\aws-api-gateway-cli-test\index.js:152:5
    at C:\Users\aamai\AppData\Roaming\npm-cache\_npx\18348\node_modules\aws-api-gateway-cli-test\node_modules\aws-sdk\lib\credentials.js:124:23
    at C:\Users\aamai\AppData\Roaming\npm-cache\_npx\18348\node_modules\aws-api-gateway-cli-test\node_modules\aws-sdk\lib\credentials.js:212:15
    at processTicksAndRejections (internal/process/task_queues.js:79:11)

I'm not too sure what I'm doing wrong. I'm trying to fix the syntax error but I'm extremely stuck :(
Can I get some help please. I'm on Windows 10!

@jonasbarsten
Copy link

@awahmed, looks like you have a \ before "content" that doesn't belong there :)

@awahmed
Copy link

awahmed commented Oct 19, 2020

@jonasbarsten That's so wierd, I removed that \ and it gave me a very similar error at the same exact spot too. I just wanted to mention I am using powershell for this. Because I brought up Command Prompt and put my original command and that ended up working!

@agam-mishra
Copy link

@awahmed did you get to a solution for your error.? I am also getting same error and cannot go pass it. Your help would be highly appreciated.

@awahmed
Copy link

awahmed commented Dec 20, 2020

@agam-mishra I used Command prompt isntead of Powershell and ran the same command and it ended up working for me. For some reason Powershell was giving me that error only. Hope that helps

@bedamatta05
Copy link

bedamatta05 commented May 24, 2021

Hello everyone I am having a problem with testing the api. When I run all the other tests in mock, my backend is updated and I see what I created,updated,deleted,etc. But when I run the command(I'm omitting alot of details. 'body' is my main question here): npx aws-api-gateway-cli-test --api-gateway-region us-east-1 --path-template /requests --method POST --body "{\"content\":\"test req\",\"amount\":\"120\",\"attachment\":\"bye.jpg\"}"

its giving me this error:

Authenticating with User Pool
Getting temporary credentials
Making API request
undefined:1
{\
 ^

SyntaxError: Unexpected token \ in JSON at position 1
    at JSON.parse (<anonymous>)
    at makeRequest (C:\Users\aamai\AppData\Roaming\npm-cache\_npx\18348\node_modules\aws-api-gateway-cli-test\index.js:179:17)
    at C:\Users\aamai\AppData\Roaming\npm-cache\_npx\18348\node_modules\aws-api-gateway-cli-test\index.js:152:5
    at C:\Users\aamai\AppData\Roaming\npm-cache\_npx\18348\node_modules\aws-api-gateway-cli-test\node_modules\aws-sdk\lib\credentials.js:124:23
    at C:\Users\aamai\AppData\Roaming\npm-cache\_npx\18348\node_modules\aws-api-gateway-cli-test\node_modules\aws-sdk\lib\credentials.js:212:15
    at processTicksAndRejections (internal/process/task_queues.js:79:11)

I'm not too sure what I'm doing wrong. I'm trying to fix the syntax error but I'm extremely stuck :(
Can I get some help please. I'm on Windows 10!

Hi @awahmed I'm getting the same error now. Can u please help me in solving ?

@satokenta940
Copy link

What tools do you use for testing, Postman or Apdiog

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

No branches or pull requests