AnomalyInnovations / aws-api-gateway-cli-test

A simple CLI to test API Gateway endpoints with IAM authorization
MIT License
121 stars 29 forks source link

Issue with body JSON parsing, on local machine, causing request to fail. #22

Open ashoukr opened 3 years ago

ashoukr commented 3 years ago

I am trying to locally test some IAM roles, however there is a problem regarding the json parsing function to read the body contents passed in the command. However, when I run it on Virtual Machine, it runs just fine. I am wondering if there are compatibility issues with this npm package and versions of node or other aws npm packages.

Using latest version: aws-api-gateway-cli-test@1.3.2

command I ran:

npx aws-api-gateway-cli-test \ --username='REDACTED' \ --password='REDACTED!' \ --user-pool-id='REDACTED' \ --app-client-id='REDACTED' \ --cognito-region='us-east-1' \ --identity-pool-id='REDACTED' \ --invoke-url='REDACTED' \ --api-gateway-region='us-east-1' \ --path-template='/notes' \ --method='POST' \ --body='{"content":"hello world", "attachment":"hello.jpg"}'

Error/bug:

Authenticating with User Pool Getting temporary credentials

Making API request /Users/REDACTED/.npm/_npx/ea84c6478cf14779/node_modules/aws-api-gateway-cli-test/index.js:172 if (argv.body.startsWith("@")) { ^

TypeError: argv.body.startsWith is not a function at makeRequest (/Users/REDACTED/.npm/_npx/ea84c6478cf14779/node_modules/aws-api-gateway-cli-test/index.js:172:17) at /Users/REDACTED/.npm/_npx/ea84c6478cf14779/node_modules/aws-api-gateway-cli-test/index.js:152:5 at /Users/REDACTED/.npm/_npx/ea84c6478cf14779/node_modules/aws-sdk/lib/credentials.js:124:23 at /Users/REDACTED/.npm/_npx/ea84c6478cf14779/node_modules/aws-sdk/lib/credentials.js:212:15 at processTicksAndRejections (node:internal/process/task_queues:75:11) npm ERR! code 1 npm ERR! path /Users/REDACTED/Serverless-Tutorial/notes-api npm ERR! command failed

Full debug Log:

0 verbose cli [
0 verbose cli   '/usr/local/bin/node',
0 verbose cli   '/usr/local/lib/node_modules/npm/bin/npm-cli.js',
0 verbose cli   'exec',
0 verbose cli   '--',
0 verbose cli   'aws-api-gateway-cli-test',
0 verbose cli   '--username=admin@example.com',
0 verbose cli   '--password=Passw0rd!',
0 verbose cli   '--user-pool-id=us-east-REDACTED',
0 verbose cli   '--app-client-id=REDACTED',
0 verbose cli   '--cognito-region=us-east-1',
0 verbose cli   '--identity-pool-id=REDACTED',
0 verbose cli   '--invoke-url=REDACTED',
0 verbose cli   '--api-gateway-region=us-east-1',
0 verbose cli   '--path-template=/notes',
0 verbose cli   '--method=POST',
0 verbose cli   '--body={"content":"hello world","attachment":"hello.jpg"}'
0 verbose cli ]
1 info using npm@7.3.0
2 info using node@v15.5.0
3 timing config:load:defaults Completed in 1ms
4 timing config:load:file:/usr/local/lib/node_modules/npm/npmrc Completed in 0ms
5 timing config:load:builtin Completed in 0ms
6 timing config:load:cli Completed in 1ms
7 timing config:load:env Completed in 0ms
8 timing config:load:file:REDACTED/Serverless-Tutorial/notes-api/.npmrc Completed in 0ms
9 timing config:load:project Completed in 1ms
10 timing config:load:file:/Users/REDACTED.npmrc Completed in 1ms
11 timing config:load:user Completed in 1ms
12 timing config:load:file:/usr/local/etc/npmrc Completed in 0ms
13 timing config:load:global Completed in 0ms
14 timing config:load:cafile Completed in 0ms
15 timing config:load:validate Completed in 1ms
16 timing config:load:setUserAgent Completed in 0ms
17 timing config:load:setEnvs Completed in 1ms
18 timing config:load Completed in 7ms
19 verbose npm-session 3437d19e45fb8a34
20 timing npm:load Completed in 15ms
21 http fetch GET 304 https://registry.npmjs.org/aws-api-gateway-cli-test 196ms (from cache)
22 timing arborist:ctor Completed in 1ms
23 timing arborist:ctor Completed in 0ms
24 timing arborist:ctor Completed in 0ms
25 timing command:exec Completed in 3676ms
26 verbose stack Error: command failed
26 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/@npmcli/promise-spawn/index.js:64:27)
26 verbose stack     at ChildProcess.emit (node:events:376:20)
26 verbose stack     at maybeClose (node:internal/child_process:1063:16)
26 verbose stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:295:5)
27 verbose pkgid notes-api@2.2.0
28 verbose cwd /Users/REDACTED/Serverless-Tutorial/notes-api
29 verbose Darwin 20.3.0
30 verbose argv "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/bin/npm-cli.js" "exec" "--" "aws-api-gateway-cli-test" "--username=admin@example.com" "--password=Passw0rd!" "--user-pool-id=us-east-REDACTED" "--app-client-id=REDACTED" "--cognito-region=us-east-1" "--identity-pool-id=us-east-1:REDACTED" "--invoke-url=REDACTED" "--api-gateway-region=us-east-1" "--path-template=/notes" "--method=POST" "--body={\"content\":\"hello world\",\"attachment\":\"hello.jpg\"}"
31 verbose node v15.5.0
32 verbose npm  v7.3.0
33 error code 1
34 error path /Users/REDACTEDServerless-Tutorial/notes-api
35 error command failed
36 error command sh -c apig-test --username=admin@example.com --password=Passw0rd! --user-pool-id=REDACTED --app-client-id=REDACTED --cognito-region=us-east-1 --identity-pool-id=us-east-1:REDACTED --invoke-url=REDACTED --api-gateway-region=us-east-1 --path-template=/notes --method=POST --body={"content":"hello world","attachment":"hello.jpg"}
37 verbose exit 1