# Comments for Test the APIs

**URL:** <https://discourse.sst.dev/t/comments-for-test-the-apis/122>\
**Category:** Chapter Comments\
**Created:** [May 9, 2018, 7:33pm UTC](https://discourse.sst.dev/t/comments-for-test-the-apis/122 "2018-05-09T19:33:16Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:33pm UTC](https://discourse.sst.dev/t/comments-for-test-the-apis/122/1 "2018-05-09T19:33:16Z")

</div>

_From @jayair on Wed Jul 19 2017 19:48:19 GMT+0000 (UTC)_  
  
Link to chapter - [http://serverless-stack.com/chapters/test-the-apis.html](http://serverless-stack.com/chapters/test-the-apis.html)  
  
_Copied from original issue: [https://github.com/AnomalyInnovations/serverless-stack-com/issues/112](https://github.com/AnomalyInnovations/serverless-stack-com/issues/112)_

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:33pm UTC](https://discourse.sst.dev/t/comments-for-test-the-apis/122/2 "2018-05-09T19:33:24Z")

</div>

_From @yashg5 on Thu Jul 20 2017 08:57:00 GMT+0000 (UTC)_  
  
Can you give us example screen shots to test API with postman using AWS signature? thanks in advance

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:33pm UTC](https://discourse.sst.dev/t/comments-for-test-the-apis/122/3 "2018-05-09T19:33:24Z")

</div>

_From @jayair on Thu Jul 20 2017 16:52:50 GMT+0000 (UTC)_  
  
@yashg5 I’m not too familiar with using Postman. Perhaps somebody else can give it a try.

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:33pm UTC](https://discourse.sst.dev/t/comments-for-test-the-apis/122/4 "2018-05-09T19:33:25Z")

</div>

_From @marshallbunch on Thu Jul 20 2017 17:35:34 GMT+0000 (UTC)_  
  
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?

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:33pm UTC](https://discourse.sst.dev/t/comments-for-test-the-apis/122/5 "2018-05-09T19:33:25Z")

</div>

_From @jayair on Thu Jul 20 2017 17:45:00 GMT+0000 (UTC)_  
  
@marshallbunch Here is a sample one that I was using. I altered some of the values around but the format should be like so.

```bash
apig-test \
--username='admin@example.com' \
--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"}'

```

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:33pm UTC](https://discourse.sst.dev/t/comments-for-test-the-apis/122/6 "2018-05-09T19:33:25Z")

</div>

_From @marshallbunch on Thu Jul 20 2017 18:00:58 GMT+0000 (UTC)_  
  
No cigar. Won’t make it past the user-pool-id.

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:33pm UTC](https://discourse.sst.dev/t/comments-for-test-the-apis/122/7 "2018-05-09T19:33:25Z")

</div>

_From @jayair on Thu Jul 20 2017 18:06:22 GMT+0000 (UTC)_  
  
@marshallbunch Hmm can I see the complete output from the command?

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:33pm UTC](https://discourse.sst.dev/t/comments-for-test-the-apis/122/8 "2018-05-09T19:33:26Z")

</div>

_From @marshallbunch on Thu Jul 20 2017 18:19:02 GMT+0000 (UTC)_  
  
Sure:

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:33pm UTC](https://discourse.sst.dev/t/comments-for-test-the-apis/122/9 "2018-05-09T19:33:26Z")

</div>

_From @manubhat90 on Thu Jul 20 2017 18:42:01 GMT+0000 (UTC)_  
  
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](https://ly55wbovq4.execute-api.us-east-1.amazonaws.com/prod)”

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:33pm UTC](https://discourse.sst.dev/t/comments-for-test-the-apis/122/10 "2018-05-09T19:33:26Z")

</div>

_From @marshallbunch on Thu Jul 20 2017 18:45:42 GMT+0000 (UTC)_  
  
did that as well.

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:33pm UTC](https://discourse.sst.dev/t/comments-for-test-the-apis/122/11 "2018-05-09T19:33:26Z")

</div>

_From @jayair on Thu Jul 20 2017 18:56:43 GMT+0000 (UTC)_  
  
@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.

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:33pm UTC](https://discourse.sst.dev/t/comments-for-test-the-apis/122/12 "2018-05-09T19:33:27Z")

</div>

_From @marshallbunch on Thu Jul 20 2017 19:12:19 GMT+0000 (UTC)_  
  
@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.

```auto
apig-test --username admin@example.com --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)

```

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:33pm UTC](https://discourse.sst.dev/t/comments-for-test-the-apis/122/13 "2018-05-09T19:33:27Z")

</div>

_From @jayair on Thu Jul 20 2017 19:15:49 GMT+0000 (UTC)_  
  
@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.

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:33pm UTC](https://discourse.sst.dev/t/comments-for-test-the-apis/122/14 "2018-05-09T19:33:27Z")

</div>

_From @tsdorsey on Fri Jul 21 2017 22:56:33 GMT+0000 (UTC)_  
  
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.

```auto
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:

```auto
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](https://canada1.discourse-cdn.com/flex032/uploads/serverless_stack/original/1X/67f5a59a2ae2957a6574003209a2a9e10e8ae477.png)

Some of the results of `serverless deploy`:

```auto
$ 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: babel-runtime@6.23.0, uuid@3.1.0
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.

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:33pm UTC](https://discourse.sst.dev/t/comments-for-test-the-apis/122/15 "2018-05-09T19:33:28Z")

</div>

_From @jayair on Fri Jul 21 2017 23:19:33 GMT+0000 (UTC)_  
  
@tsdorsey Thanks for the details. As a quick sanity check, can I see your `package.json` and `serverless.yml`?

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:33pm UTC](https://discourse.sst.dev/t/comments-for-test-the-apis/122/16 "2018-05-09T19:33:28Z")

</div>

_From @tsdorsey on Sat Jul 22 2017 01:13:48 GMT+0000 (UTC)_  
  
@jayair I should have done this before I posted.

> **[tsdorsey/sls-notes-app](https://github.com/tsdorsey/sls-notes-app)**
>
> serverless-stack.com walkthrough test. Contribute to tsdorsey/sls-notes-app development by creating an account on GitHub.

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.

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:33pm UTC](https://discourse.sst.dev/t/comments-for-test-the-apis/122/17 "2018-05-09T19:33:28Z")

</div>

_From @marshallbunch on Sat Jul 22 2017 01:39:06 GMT+0000 (UTC)_  
  
@tsdorsey Good catch. It appears I’m experiencing the same issue.

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:33pm UTC](https://discourse.sst.dev/t/comments-for-test-the-apis/122/18 "2018-05-09T19:33:28Z")

</div>

_From @tsdorsey on Sat Jul 22 2017 03:00:28 GMT+0000 (UTC)_  
  
@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?

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:33pm UTC](https://discourse.sst.dev/t/comments-for-test-the-apis/122/19 "2018-05-09T19:33:29Z")

</div>

_From @tsdorsey on Sat Jul 22 2017 03:24:15 GMT+0000 (UTC)_  
  
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… ☹

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:33pm UTC](https://discourse.sst.dev/t/comments-for-test-the-apis/122/20 "2018-05-09T19:33:29Z")

</div>

_From @navinkumarr on Sat Jul 22 2017 11:52:12 GMT+0000 (UTC)_  
  
Getting 403 response

```bash
Authenticating with User Pool
Getting temporary credentials
Making API request
{ status: 403,
  statusText: 'Forbidden',
  data: { message: 'Forbidden' } }

```

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