# Test the Configured APIs

**URL:** <https://discourse.sst.dev/t/test-the-configured-apis/179>\
**Category:** Chapter Comments\
**Created:** [May 9, 2018, 11:20pm UTC](https://discourse.sst.dev/t/test-the-configured-apis/179 "2018-05-09T23:20:41Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [May 9, 2018, 11:20pm UTC](https://discourse.sst.dev/t/test-the-configured-apis/179/1 "2018-05-09T23:20:41Z")

</div>

Link to chapter - [https://serverless-stack.com/chapters/test-the-configured-apis.html](https://serverless-stack.com/chapters/test-the-configured-apis.html)

---

<div class="post-metadata">

**Author:** ![obliviga](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/obliviga/32/117_2.png) [@obliviga](https://discourse.sst.dev/u/obliviga)\
**Post date:** [May 15, 2018, 9:25pm UTC](https://discourse.sst.dev/t/test-the-configured-apis/179/2 "2018-05-15T21:25:26Z")

</div>

Hello, I’m getting a 403 error after running `npx aws-api-gateway-cli-test`. I went through the steps on troubleshooting, but still getting the same problem. Here is the command with the options and following error:

```bash
    npx aws-api-gateway-cli-test \
    --username='admin@example.com' \
    --password='Password123!' \
    --user-pool-id='us-west-2_CtNOyowR4' \
    --app-client-id='7o2d13dnd76cr32bmalk5btdd' \
    --cognito-region='us-west-2' \
    --identity-pool-id='us-west-2:4bde746f-46e1-45f6-91b9-8ffdabf4f300' \
    --invoke-url='https://s8xk7c9j6j.execute-api.us-west-2.amazonaws.com/prod' \
    --api-gateway-region='us-west-2' \
    --path-template='/notes' \
    --method='POST' \
    --body='{"content":"hello world","attachment":"hello.jpg"}'
    npx: installed 103 in 13.668s
    Authenticating with User Pool
    Getting temporary credentials
    Making API request
    { status: 403,
      statusText: 'Forbidden',
      data: 
       { Message: 'User: arn:aws:sts::242648831828:assumed-role/Cognito_notesidentitypoolAuth_Role/CognitoIdentityCredentials is not authorized to perform: execute-api:Invoke on resource: arn:aws:execute-api:us-west-2: ******** 1828:s8xk7c9j6j/prod/POST/notes' } }

```

Here is a screenshot showing that the role has been allowed:

 ![simSuccess](https://canada1.discourse-cdn.com/flex032/uploads/serverless_stack/original/1X/50e6fcb9730153f8b06939a9ebaf89c2511fa137.png)

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [May 15, 2018, 9:49pm UTC](https://discourse.sst.dev/t/test-the-configured-apis/179/3 "2018-05-15T21:49:32Z")

</div>

Hmm I’m not sure if there was a typo in the simulator screenshot but the API Gateway ID `CtNOyowR4` is not the same as the one you are making a request to using the `aws-api-gateway-cli-test` command.

---

<div class="post-metadata">

**Author:** ![obliviga](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/obliviga/32/117_2.png) [@obliviga](https://discourse.sst.dev/u/obliviga)\
**Post date:** [May 15, 2018, 10:02pm UTC](https://discourse.sst.dev/t/test-the-configured-apis/179/4 "2018-05-15T22:02:57Z")

</div>

What do you mean? I can’t find the inconsistency ☹

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [May 15, 2018, 11:44pm UTC](https://discourse.sst.dev/t/test-the-configured-apis/179/5 "2018-05-15T23:44:32Z")

</div>

> [@obliviga](#):
>
> `https://s8xk7c9j6j.execute-api.us-west-2.amazonaws.com/prod`

That’s the API you are invoking but in the screenshot for the policy simulator, it looks like the API Gateway ID is `CtNOyowR4`. You should test it against `s8xk7c9j6j`.

---

<div class="post-metadata">

**Author:** ![obliviga](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/obliviga/32/117_2.png) [@obliviga](https://discourse.sst.dev/u/obliviga)\
**Post date:** [May 16, 2018, 1:36am UTC](https://discourse.sst.dev/t/test-the-configured-apis/179/6 "2018-05-16T01:36:05Z")

</div>

Cool, thanks. Looked like that command worked with status 200!

---

<div class="post-metadata">

**Author:** ![benwalker](https://avatars.discourse-cdn.com/v4/letter/b/848f3c/32.png) [@benwalker](https://discourse.sst.dev/u/benwalker)\
**Post date:** [June 21, 2018, 2:52am UTC](https://discourse.sst.dev/t/test-the-configured-apis/179/7 "2018-06-21T02:52:49Z")

</div>

I have followed the steps in this chapter, but I am also running into an issue when running `npx aws-api-gateway-cli-test`. The output shows:

```auto
npx: installed 103 in 3.614s
Authenticating with User Pool
User does not exist.

```

When I navigate to the Cognito user pool in AWS, I do see my test user, but I do NOT see this test user in the Cognito identity pool. Should I?

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [June 21, 2018, 5:40pm UTC](https://discourse.sst.dev/t/test-the-configured-apis/179/8 "2018-06-21T17:40:28Z")

</div>

This error specifically is pointing to you missing your User Pool user. Maybe the credentials you used were incorrect?

---

<div class="post-metadata">

**Author:** ![hosmer](https://avatars.discourse-cdn.com/v4/letter/h/3e96dc/32.png) [@hosmer](https://discourse.sst.dev/u/hosmer)\
**Post date:** [July 3, 2018, 8:27pm UTC](https://discourse.sst.dev/t/test-the-configured-apis/179/9 "2018-07-03T20:27:56Z")

</div>

I get following error, please look into it:

```bash
npx: installed 103 in 12.345s
Authenticating with User Pool
Getting temporary credentials
Making API request
{ status: 500,
  statusText: 'Internal Server Error',
  data: { status: false } }

```

---

<div class="post-metadata">

**Author:** ![hosmer](https://avatars.discourse-cdn.com/v4/letter/h/3e96dc/32.png) [@hosmer](https://discourse.sst.dev/u/hosmer)\
**Post date:** [July 4, 2018, 12:24am UTC](https://discourse.sst.dev/t/test-the-configured-apis/179/10 "2018-07-04T00:24:54Z")

</div>

More on this

```auto
{
  "errorMessage": "Unexpected token u in JSON at position 0",
  "errorType": "SyntaxError",
  "stackTrace": [
    "JSON.parse (<anonymous>)",
    "_callee$ (/var/task/webpack:/create.js:6:21)",
    "tryCatch (/var/task/node_modules/regenerator-runtime/runtime.js:62:40)",
    "Generator.invoke [as _invoke] (/var/task/node_modules/regenerator-runtime/runtime.js:296:22)",
    "Generator.prototype.(anonymous function) [as next] (/var/task/node_modules/regenerator-runtime/runtime.js:114:21)",
    "step (/var/task/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)",
    "/var/task/node_modules/babel-runtime/helpers/asyncToGenerator.js:35:14",
    "new Promise (<anonymous>)",
    "new F (/var/task/node_modules/core-js/library/modules/_export.js:36:28)",
    "/var/task/node_modules/babel-runtime/helpers/asyncToGenerator.js:14:12"
  ]
}

```

---

<div class="post-metadata">

**Author:** ![hosmer](https://avatars.discourse-cdn.com/v4/letter/h/3e96dc/32.png) [@hosmer](https://discourse.sst.dev/u/hosmer)\
**Post date:** [July 4, 2018, 2:46am UTC](https://discourse.sst.dev/t/test-the-configured-apis/179/11 "2018-07-04T02:46:52Z")

</div>

Never mind its resolved!

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [July 5, 2018, 7:19pm UTC](https://discourse.sst.dev/t/test-the-configured-apis/179/12 "2018-07-05T19:19:15Z")

</div>

Oh what was the issue?

---

<div class="post-metadata">

**Author:** ![ggg](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@ggg](https://discourse.sst.dev/u/ggg)\
**Post date:** [July 13, 2018, 8:37pm UTC](https://discourse.sst.dev/t/test-the-configured-apis/179/13 "2018-07-13T20:37:03Z")

</div>

Hi jayair,

I’m getting a 500 trying to test the API. Could you give me suggestions as to how to go about debugging the error? Thanks vm!

— below is my test run after creating a test user

```bash
    bash-3.2$ npx aws-api-gateway-cli-test \
    --username='admin@example.com' \
    --password='Passw0rd!' \
    --user-pool-id='us-east-2_ftYJN6YTE' \
    --app-client-id='2etl65d6u2p5lsjrn1u9cmhkh1' \
    --cognito-region='us-east-2' \
    --identity-pool-id='us-east-2:9c7bbdf6-ebf7-4f68-8408-b17cec95e759' \
    --invoke-url='https://cq6qo7q5n7.execute-api.us-east-2.amazonaws.com/dev' \
    --api-gateway-region='us-east-2' \
    --path-template='/notes' \
    --method='POST' \
    --body='{"content":"hello-dev0-world","attachment":"hello.jpg"}'
    npx: installed 103 in 3.243s
    Authenticating with User Pool
    Getting temporary credentials
    Making API request
    { status: 500,
      statusText: 'Internal Server Error',
      data: { status: false } }
    bash-3.2$ 

```

– below is the end of the build log

```auto
Stack Outputs
AttachmentsBucketName: sls-api-dev-attachmentsbucket-1d6ippxpi7ewy
UserPoolClientId: 2etl65d6u2p5lsjrn1u9cmhkh1
UserPoolId: us-east-2_ftYJN6YTE
DeleteLambdaFunctionQualifiedArn: arn:aws:lambda:us-east-2:868242285281:function:sls-api-dev-delete:2
CreateLambdaFunctionQualifiedArn: arn:aws:lambda:us-east-2:868242285281:function:sls-api-dev-create:2
GetLambdaFunctionQualifiedArn: arn:aws:lambda:us-east-2:868242285281:function:sls-api-dev-get:2
UpdateLambdaFunctionQualifiedArn: arn:aws:lambda:us-east-2:868242285281:function:sls-api-dev-update:2
IdentityPoolId: us-east-2:9c7bbdf6-ebf7-4f68-8408-b17cec95e759
BillingLambdaFunctionQualifiedArn: arn:aws:lambda:us-east-2:868242285281:function:sls-api-dev-billing:1
ListLambdaFunctionQualifiedArn: arn:aws:lambda:us-east-2:868242285281:function:sls-api-dev-list:2
ServiceEndpoint: https://cq6qo7q5n7.execute-api.us-east-2.amazonaws.com/dev
ServerlessDeploymentBucketName: sls-api-dev-serverlessdeploymentbucket-1fvqmcj3wd4ef

====================
🗑 Cleanup
====================

2018/07/12 21:32:48 Post deploy cleanup

✅ Build v1 successfully deployed!

```

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [July 16, 2018, 1:21am UTC](https://discourse.sst.dev/t/test-the-configured-apis/179/14 "2018-07-16T01:21:56Z")

</div>

For 500 errors, it is most likely coming from your Lambda functions. You can add a `console.log` and check the logs in [Seed](https://seed.run) to debug the issue. We cover how to check the logs in this chapter:

> **[Monitoring Deployments in Seed](https://serverless-stack.com/chapters/monitoring-deployments-in-seed.html#view-logs-and-metrics)**
>
> We can monitor our Serverless deployments in Seed by viewing CloudWatch logs and metrics for our Lambda functions and our API Gateway endpoints. We can also enable access logs for API Gateway from the Seed console.

---

<div class="post-metadata">

**Author:** ![ggg](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@ggg](https://discourse.sst.dev/u/ggg)\
**Post date:** [July 16, 2018, 9:41am UTC](https://discourse.sst.dev/t/test-the-configured-apis/179/15 "2018-07-16T09:41:23Z")

</div>

Thanks Jay!

The lambda function never gets a chance to be executed no matter how many console.log lines I add to the code. It 500s before getting to the code as far as I can tell.

I think the cause is the hard-coded “us-east-1” in the libs/ sub dir:

> <https://github.com/AnomalyInnovations/serverless-stack-demo-api/blob/master/libs/dynamodb-lib.js>

All my stuff lives in Ohio, us-east-2.

I suspect anyone whose region is different from what’s in that libs file will run into the same problem I have.

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [July 18, 2018, 6:20pm UTC](https://discourse.sst.dev/t/test-the-configured-apis/179/16 "2018-07-18T18:20:28Z")

</div>

Ah yeah. That is on our todo to remove that line. You shouldn’t need that since we are setting the region through the `serverless.yml`.

---

<div class="post-metadata">

**Author:** ![Pottaz](https://avatars.discourse-cdn.com/v4/letter/p/b5ac83/32.png) [@Pottaz](https://discourse.sst.dev/u/Pottaz)\
**Post date:** [July 24, 2018, 7:17am UTC](https://discourse.sst.dev/t/test-the-configured-apis/179/17 "2018-07-24T07:17:28Z")

</div>

Hi  
I am getting a Forbidden error and can’t seem to trace its origin.

```
    npx: installed 105 in 14.884s
Authenticating with User Pool
Getting temporary credentials
Making API request
{ status: 403,
  statusText: 'Forbidden',
  data: 
   { message: 'Credential should be scoped to a valid region, not \'us-east-1\'. ' } }

```

I am using ‘eu-west-1’ and have changed it within the code.

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [July 27, 2018, 11:18pm UTC](https://discourse.sst.dev/t/test-the-configured-apis/179/18 "2018-07-27T23:18:25Z")

</div>

I’m not sure if this is related but we used to have the `us-east-1` hardcoded in the `dynamodb-lib.js`. We updated the tutorial recently but you might still have that in there.

We were talking about it above:

> [@Test the Configured APIs](https://discourse.sst.dev/t/test-the-configured-apis/179/15):
>
> Thanks Jay! The lambda function never gets a chance to be executed no matter how many console.log lines I add to the code. It 500s before getting to the code as far as I can tell. I think the cause is the hard-coded “us-east-1” in the libs/ sub dir: All my stuff lives in Ohio, us-east-2. I suspect anyone whose region is different from what’s in that libs file will run into the same problem I have.

---

<div class="post-metadata">

**Author:** ![ChrisWill](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/chriswill/32/208_2.png) [@ChrisWill](https://discourse.sst.dev/u/ChrisWill)\
**Post date:** [August 29, 2018, 8:41am UTC](https://discourse.sst.dev/t/test-the-configured-apis/179/19 "2018-08-29T08:41:57Z")

</div>

I’m having the same problem after I implemented the new deployment methods for the deployment automation.  
I’ve changed the lib back when it all worked but it keeps getting me the same error.  
Any help? Is there something I can edit?

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [August 29, 2018, 6:56pm UTC](https://discourse.sst.dev/t/test-the-configured-apis/179/20 "2018-08-29T18:56:43Z")

</div>

What’s the error you are having again?

[Next page](https://discourse.sst.dev/t/test-the-configured-apis/179.md?page=2)
