In this chapter of the tutorial <https://serverles...
# help
k
In this chapter of the tutorial https://serverless-stack.com/chapters/secure-our-serverless-apis.html They tell you to make a curl request to test the auth. This is what my curl req looks like
Copy code
npx aws-api-gateway-cli-test --username <mailto:test@gmail.com|test@gmail.com> --password 12345Foo! --user-pool-id us-east-1_I8XLnM67Q --app-client-id 44hqn436m45aa92j9vkh7pjdfn --cognito-region us-east-1 --identity-pool-id us-east-1:966cd055-29d0-4f48-ba65-3326cf9dea63 --invoke-url <https://d8cdv8pdh4.execute-api.us-east-1.amazonaws.com> --api-gateway-region us-east-1 --path-template /notes --method POST --body "{\"content\":\"h\",\"attachment\":\"h.jpg\"}"
But I get an error saying
{\ SyntaxError: Unexpected token \ in JSON at position 1
I have even tried this
Copy code
npx aws-api-gateway-cli-test --username <mailto:test@gmail.com|test@gmail.com> --password 12345Foo! --user-pool-id us-east-1_I8XLnM67Q --app-client-id 44hqn436m45aa92j9vkh7pjdfn --cognito-region us-east-1 --identity-pool-id us-east-1:966cd055-29d0-4f48-ba65-3326cf9dea63 --invoke-url <https://d8cdv8pdh4.execute-api.us-east-1.amazonaws.com> --api-gateway-region us-east-1 --path-template /notes --method POST --body '{"content":"d","attachment":"hello.jpg"}'
r
I haven’t used that utility myself but looking at the code it seems to b just doing
Copy code
body = JSON.parse(argv.body);
Therefore, it could be a dodgy character in your body, maybe the double quotes are invalid, I don’t think you need to escape the quotes in there, so your second example looks like it should work. I just copied and pasted your example and I get
Copy code
Authenticating with User Pool
Getting temporary credentials
Making API request
{
  status: 500,
  statusText: 'Internal Server Error',
  data: { message: 'Internal Server Error' }
}
Where do you see the JSON parse error?
k
This is the full log
Copy code
Authenticating with User Pool
Getting temporary credentials
Making API request
undefined:1
{content:d,attachment:hello.jpg}
 ^

SyntaxError: Unexpected token c in JSON at position 1
    at JSON.parse (<anonymous>)
    at makeRequest (C:\Users\kenny\AppData\Local\npm-cache\_npx\ea84c6478cf14779\node_modules\aws-api-gateway-cli-test\index.js:179:17)
    at C:\Users\kenny\AppData\Local\npm-cache\_npx\ea84c6478cf14779\node_modules\aws-api-gateway-cli-test\index.js:152:5
    at C:\Users\kenny\AppData\Local\npm-cache\_npx\ea84c6478cf14779\node_modules\aws-sdk\lib\credentials.js:124:23
    at C:\Users\kenny\AppData\Local\npm-cache\_npx\ea84c6478cf14779\node_modules\aws-sdk\lib\credentials.js:212:15
    at processTicksAndRejections (internal/process/task_queues.js:77:11)
when running the second one
r
From Cloudwatch?
k
???
just in the console
r
That’s what you get in your terminal?
k
yeg
yes
r
Weird, I don’t, running the same thing. Paste this:
Copy code
npx aws-api-gateway-cli-test --username <mailto:test@gmail.com|test@gmail.com> --password 12345Foo! --user-pool-id us-east-1_I8XLnM67Q --app-client-id 44hqn436m45aa92j9vkh7pjdfn --cognito-region us-east-1 --identity-pool-id us-east-1:966cd055-29d0-4f48-ba65-3326cf9dea63 --invoke-url <https://d8cdv8pdh4.execute-api.us-east-1.amazonaws.com> --api-gateway-region us-east-1 --path-template /notes --method POST --body '{"content":"d","attachment":"hello.jpg"}'
k
I am on Windows if that makes a difference
r
Possibly, I’m using a Mac
k
I am not seeing that
r
Seems like it’s something specific to your terminal
k
Im using windows termina;
r
Sorry, long time since I used Windows so can’t really help
k
👍🥲
f
@Jay any idea about this? Do you have to escape the command differently on windows?
j
Yeah it is different. But it also depends on your windows setup. I don't use windows so I don't know the exact difference but people do report it.
Does the windows version in the chapter not work?
k
I AM using the windows version
space separated
k
@Kenny are you using Powershell or CMD as your terminal?
k
yes
powershell
k
which one 😉?
ok
k
also tried it on cmd
k
@Kenny I gave it a try as well under Windows + noticed the same behaviour. It could be be a bug in the aws cli command. What worked though was calling
bash
in powershel + then sending the command (which is using WSL in that case)
so this seems to be related to how arguments with `"`are treated in Windows shells + escapng (while working fine e.g. for
echo
in Powershell ) simply seems to fail
k
so I should run
bash
then
Copy code
npx aws-api-gateway-cli-test --username <mailto:test@gmail.com|test@gmail.com> --password 12345Foo! --user-pool-id us-east-1_I8XLnM67Q --app-client-id 44hqn436m45aa92j9vkh7pjdfn --cognito-region us-east-1 --identity-pool-id us-east-1:966cd055-29d0-4f48-ba65-3326cf9dea63 --invoke-url <https://d8cdv8pdh4.execute-api.us-east-1.amazonaws.com> --api-gateway-region us-east-1 --path-template /notes --method POST --body '{"content":"d","attachment":"hello.jpg"}'
??
k
yes, that works for me under windows (but requires the subsystem for Linux to be enabled / installed)
k
Doesn't work for me
k
Copy code
$ bash                                                                                                  Welcome to Ubuntu 20.04.4 LTS (GNU/Linux 5.10.43.3-microsoft-standard-WSL2+ x86_64) ...

$npx aws-api-gateway-cli-test --username <mailto:test@gmail.com|test@gmail.com> --password 12345Foo! --user-pool-id us-east-1_I8XLnM67Q --app-client-id 44hqn436m45aa92j9vkh7pjdfn --cognito-region us-east-1 --identity-pool-id us-east-1:966cd055-29d0-4f48-ba65-3326cf9dea63 --invoke-url <https://d8cdv8pdh4.execute-api.us-east-1.amazonaws.com> --api-gateway-region us-east-1 --path-template /notes --method POST --body '{"content":"h","attachment":"h.jpg"}'
k
No welcome message for me
k
then WSL might not be installed
k
how to install?
after WSL, you'll also need to install nodejs
k
olrite, I do have that one.
i ran
wsl --install -d Ubuntu
k
with both present, the npx should work
https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-20-04 (Option 2) might be an alternative to NVM to get a modern nodejs on the system
in some cases, you might need to limit the WSL2 memory with a config file if you are using it regularly (especially for Docker)
VSCode also allows creating a bash terminal directly like this ( as long as WSL is installed)
k
ahh😮
j
Thanks for helping out @Klaus! Really appreciate it cos we aren’t great with windows here.
k
@Jay - I also prefer Linux, but have a Windows machine due to some other work requirements and not being to fond of the missing keys on MACs (one of the areas where Apple overoptimized to my mind) 😜