Comments for Test the APIs

I’m having the same issue, did you resolve it ?

I’m having an issue where my body object is not being processed.

My body flag is: --body='{"content":"hello test","attachment":"hello-test.jpg"}'

but I get the following response (removed userID):

{ status: 200,
  statusText: 'OK',
   { userId: 'UserID',
     noteId: '04627170-451d-11ea-a651-958c37f77029',
     createdAt: 1580580151815 } 

I get an entry in my DynamoDB table and my code is exact to the tutorial.

My CloudWatch logs reveals:

  • Method request body before transformations:
    "content": "hello test",
    "attachment": "hello-test.jpg"
  • the create function in invoked, but then logs
  • (I removed the userID) Endpoint response body before transformations:
    "statusCode": 200,
    "headers": {
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Credentials": true
    "body": "{\"userId\":\"USERID\",\"noteId\":\"04627170-451d-11ea-a651-958c37f77029\",\"createdAt\":1580580151815}"

Not sure why my body json won’t get processed. Any ideas?

I’ve resolved it, insted of “” put ‘’

“{“content”:“hello world”,“attachment”:“hello.jpg”}”

‘{“content”:“hello world”,“attachment”:“hello.jpg”}’

1 Like

Thanks for replying…I used the single quotes around the cli command, the double quotes you see is what I copied from CloudWatch logs

I am experiencing a similar issue discussed before, but I did not seem to find a solution here. I am receiving this message:

{ status: 403,
  statusText: 'Forbidden',
   { message: 'Credential should be scoped to a valid region, not \'us-east-1\'. ' } }

My cli command is as follows:

npx aws-api-gateway-cli-test --username='' --password='Somepassword' --user-pool-id='us-east-2_XXXXXX' --app-client-id='xxxxxxxxxxxxxxxxx' --cognito-region='us-east-2' --identity-pool-id='us-east-2:xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' --invoke-url='' api-gateway-region='us-east-2' --path-template='/notes' --method='POST' --body='{"content":"hello world","attachment":"hello.jpg"}'

I’ve double checked everything on AWS and ensured it was set to us-east-2. I even checked my default settings in .aws

Maybe I am missing something obvious but I’ve quadruple checked everything and at a loss what is off.

okay, so after posting the markdown it was painfully obvious to me that I was missing the ‘–’ before 'api-gateway-region.


Are you still having issues? Can you console.log inside your Lambda function to see whats going on?

For anyone else having this error:

  status: 502,
  statusText: 'Bad Gateway',
  data: { message: 'Internal server error' }

One possible solution is to escape the string at the body option


I’m consoling out data & params.Items in create.js but nothing shows up in my CloudWatch logs for the /aws/lambda/notes-app-api-dev-create lambda & my gateway logs are the same as I posted before.

First I would make sure that your create functions are actually getting called. If they are, then I would find the spot where it is failing.

From your description it sounds like it’s not getting called at all?


Test the API

npx aws-api-gateway-cli-test \
--username='' \
--password='Passw0rd!' \
--user-pool-id='YOUR_DEV_COGNITO_USER_POOL_ID' \
--app-client-id='YOUR_DEV_COGNITO_APP_CLIENT_ID' \
--cognito-region='YOUR_DEV_COGNITO_REGION' \
--identity-pool-id='YOUR_DEV_IDENTITY_POOL_ID' \
--invoke-url='YOUR_DEV_API_GATEWAY_URL' \
--api-gateway-region='YOUR_DEV_API_GATEWAY_REGION' \
--path-template='/notes' \
--method='POST' \
--body='{"content":"hello world","attachment":"hello.jpg"}'

To make the above command work in Windows Command Prompt, remove the =, \, ’ and have the command in a single line else they will be read as multiple commands. --body message should be as shown in the sample below:

npx aws-api-gateway-cli-test --username []( --password  Passw0rd! --user-pool-id YOUR_DEV_COGNITO_USER_POOL_ID --app-client-id YOUR_DEV_COGNITO_APP_CLIENT_ID --cognito-region  YOUR_DEV_COGNITO_REGION --identity-pool-id  YOUR_DEV_IDENTITY_POOL_ID --invoke-url YOUR_DEV_API_GATEWAY_URL --api-gateway-region  YOUR_DEV_API_GATEWAY_REGION --path-template  /notes --method  POST --body **"{\"content\":\"hello world\",\"attachment\":\"hello.jpg\"}"**

In Windows PowerShell, the difference is in --body (Double quotes is typed twice. That is one way the command works in PowerShell):

npx aws-api-gateway-cli-test --username []( --password Passw0rd! --user-pool-id YOUR_DEV_COGNITO_USER_POOL_ID --app-client-id YOUR_DEV_COGNITO_APP_CLIENT_ID --cognito-region YOUR_DEV_COGNITO_REGION --identity-pool-id YOUR_DEV_IDENTITY_POOL_ID --invoke-url YOUR_DEV_API_GATEWAY_URL --path-template /notes --method POST --body **'{""content"":""hello world"",""attachment"":""hello.jpg""}'**

Thank you so much for sharing this :pray:t5:

The npx aws-api-gateway-cli-test works out just fine for the dev stage:

  status: 200,
  statusText: 'OK',
  data: [
      ProductId: '456d7760-6119-11ea-ba0b-1f24cdb58353',
      UserId: 'eu-central-1:89e011d5-907a-4375-ba19-b7b9d4dca4e0',
      CreatedAt: 1583657175510

but for the prod stage I get an empty data array:

{ status: 200, statusText: 'OK', data: [] }

This is my call to prod:

npx aws-api-gateway-cli-test \
--username='' \
--password='Passw0rd!' \
--user-pool-id='eu-central-1_c8D3g4hxv' \
--app-client-id='7bsormil1soo7e1mpgkrpk4c64' \
--cognito-region='eu-central-1' \
--identity-pool-id='eu-central-1:58e6270f-f45b-4fe0-a876-a6546350d6c5' \
--invoke-url='' \
--api-gateway-region='eu-central-1' \

And this is my repo:

Appreciate any ideas on what could have happened :slight_smile:

I’ve made some changes to the key schema that might have broken the implementation. Still, the discrepancy between the output between the prod and dev stages is a bit weird.

Appreciate you sharing this!

403: Forbidden - I read the entire thread and tried all of the solutions suggested, and still got this error.

On a hunch based on some JSON issues I saw someone in the thread have I changed this:

--body='{"content":"hello world"}'

to this


Was able to successfully hit my API with a 200 OK.

I can’t seem to format JSON in a way that the aws-api-gateway-cli-test will accept.

Had same issue on windows. Fixed it by having body as
–body ‘{ ““content””: ““hello world””, ““attachment””:"“hello.jpg”" }’

Over and over I was getting 403s when running the npx aws-api-gateway-cli-test

CognitoIdentityCredentials is not authorized to perform: execute-api:Invoke on resource

I had to go back to the Policy Document and create a new policy with less stringent InvokeFunction Resources for that cognito role like this …


        "Effect": "Allow",
        "Action": ["execute-api:Invoke"],
        "Resource": ["arn:aws:execute-api:us-east-1:*:8zXXXXh5/*/*/*"]


        "Effect": "Allow",
        "Action": ["execute-api:Invoke"],
        "Resource": ["*"]

Really not happy about having to do this – but after 2 hours, I had no choice. Anyone have similar issues?

I found these comments very helpful and it resolved my issues …

You can check if the IAM Role has been set properly by going to your AWS Console

IAM -> Roles -> Cognito_notesAuth_Role -> oneClick_Cognito_notesAuth_Role_XXXXXXXXX -> Edit Policy -> JSON:

Just had to re-copy/paste of the code from the tutorial with the properly set app values as guided in the tutorial and it worked for me.


Glad you figure it out. These are super annoying to deal with.

1 Like

This fixed it for me as well. Somehow my original policy edit did not get saved. Thanks for this tip.