# Add a Get Note API

**URL:** <https://discourse.sst.dev/t/add-a-get-note-api/132>\
**Category:** Chapter Comments\
**Created:** [May 9, 2018, 7:57pm UTC](https://discourse.sst.dev/t/add-a-get-note-api/132 "2018-05-09T19:57:35Z")\
**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:57pm UTC](https://discourse.sst.dev/t/add-a-get-note-api/132/1 "2018-05-09T19:57:35Z")

</div>

_From @jayair on Mon Apr 10 2017 00:59:46 GMT+0000 (UTC)_  
  
Link to chapter - [http://serverless-stack.com/chapters/add-a-get-note-api.html](http://serverless-stack.com/chapters/add-a-get-note-api.html)  
  
_Copied from original issue: [https://github.com/AnomalyInnovations/serverless-stack-com/issues/24](https://github.com/AnomalyInnovations/serverless-stack-com/issues/24)_

---

<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:57pm UTC](https://discourse.sst.dev/t/add-a-get-note-api/132/2 "2018-05-09T19:57:37Z")

</div>

_From @willybeans on Fri May 12 2017 02:16:37 GMT+0000 (UTC)_  
  
Getting this when running the mock noteId parameter (serverless webpack invoke --function get --path event.json)

Type Error ---------------------------------------------

```
 Cannot read property 'handler' of undefined
```

---

<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:57pm UTC](https://discourse.sst.dev/t/add-a-get-note-api/132/3 "2018-05-09T19:57:37Z")

</div>

_From @jayair on Fri May 12 2017 17:23:03 GMT+0000 (UTC)_  
  
@willybeans can you check your `serverless.yml` and look for the `handler` property?

---

<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:57pm UTC](https://discourse.sst.dev/t/add-a-get-note-api/132/4 "2018-05-09T19:57:37Z")

</div>

_From @willybeans on Fri May 12 2017 19:23:45 GMT+0000 (UTC)_  
  
@jayair here is the bottom part of the file:

```auto
  get:
    # Defines an HTTP API endpoint that calls the main function in get.js
    # - path: url path is /notes/{id}
    # - method: GET request
    handler: get.main
    events:
      - http:
          path: notes/{id}
          method: get
          cors: true
          authorizer:
            arn: arn:aws:cognito-idp:us-east-2:433151866650:userpool/us-east-2_mttWckAZq 

```

---

<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:57pm UTC](https://discourse.sst.dev/t/add-a-get-note-api/132/5 "2018-05-09T19:57:37Z")

</div>

_From @fwang on Fri May 12 2017 21:26:32 GMT+0000 (UTC)_  
  
@willybeans this error means the `get` handler was not found in serverless.yml. Could you share the rest of your serverless.yml file?

---

<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:57pm UTC](https://discourse.sst.dev/t/add-a-get-note-api/132/6 "2018-05-09T19:57:37Z")

</div>

_From @willybeans on Sat May 13 2017 03:16:15 GMT+0000 (UTC)_  
  
@fwang

```auto
service: notes-app-api

plugins:
  - serverless-webpack

custom:
  webpackIncludeModules: true

provider:
  name: aws
  runtime: nodejs6.10
  stage: prod
  region: us-east-2

  iamRoleStatements:
    - Effect: Allow
      Action:
        - dynamodb:DescribeTable
        - dynamodb:Query
        - dynamodb:Scan
        - dynamodb:GetItem
        - dynamodb:PutItem
        - dynamodb:UpdateItem
        - dynamodb:DeleteItem
      Resource: "arn:aws:dynamodb:us-east-1:*:*"

  get:
    # Defines an HTTP API endpoint that calls the main function in get.js
    # - path: url path is /notes/{id}
    # - method: GET request
    handler: get.main
    events:
      - http:
          path: notes/{id}
          method: get
          cors: true
          authorizer:
            arn: arn:aws:cognito-idp:us-east-2:433151866650:userpool/us-east-2_mttWckAZq

```

---

<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:57pm UTC](https://discourse.sst.dev/t/add-a-get-note-api/132/7 "2018-05-09T19:57:38Z")

</div>

_From @jayair on Sat May 13 2017 23:19:06 GMT+0000 (UTC)_  
  
@willybeans just noticed that you are missing the `functions` block. Have a look at the `serverless.yml` from this chapter - [https://github.com/AnomalyInnovations/serverless-stack-demo-api/blob/add-a-get-note-api/serverless.yml#L29](https://github.com/AnomalyInnovations/serverless-stack-demo-api/blob/add-a-get-note-api/serverless.yml#L29).

Notice, the `get` block is inside the `functions` block.

---

<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:57pm UTC](https://discourse.sst.dev/t/add-a-get-note-api/132/8 "2018-05-09T19:57:38Z")

</div>

_From @Jaikant on Sun May 21 2017 08:11:59 GMT+0000 (UTC)_  
  
I had to mark the main function as ‘async’ to avoid the error  
SyntaxError: await is a reserved word

---

<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:57pm UTC](https://discourse.sst.dev/t/add-a-get-note-api/132/9 "2018-05-09T19:57:38Z")

</div>

_From @jayair on Sun May 21 2017 19:05:23 GMT+0000 (UTC)_  
  
@Jaikant but isn’t it already? [https://github.com/AnomalyInnovations/serverless-stack-demo-api/blob/add-a-get-note-api/get.js#L4](https://github.com/AnomalyInnovations/serverless-stack-demo-api/blob/add-a-get-note-api/get.js#L4)

Or do you mean something else?

---

<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:57pm UTC](https://discourse.sst.dev/t/add-a-get-note-api/132/10 "2018-05-09T19:57:39Z")

</div>

_From @Jaikant on Mon May 22 2017 05:25:28 GMT+0000 (UTC)_  
  
I seem to have missed that, maybe while moving through the chapters. thanks 🙂

---

<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:57pm UTC](https://discourse.sst.dev/t/add-a-get-note-api/132/11 "2018-05-09T19:57:39Z")

</div>

_From @idowolf on Mon Jun 12 2017 14:18:39 GMT+0000 (UTC)_  
  
When I run the command

`serverless webpack invoke --function get --path mocks/get-event.json`  
I’m getting

```auto
Serverless: Bundling with Webpack...
Time: 617ms
     Asset Size Chunks Chunk Names
 create.js 5.8 kB 0 [emitted] create
    get.js 5.88 kB 1 [emitted] get
handler.js 2.28 kB 2 [emitted] handler
Serverless: Run function get...
{ statusCode: 500,
  headers: 
   { 'Access-Control-Allow-Origin': '*',
     'Access-Control-Allow-Credentials': true },
  body: '{"status":false,"error":"Item not found."}' }

```

But when I ran the “create” command before it went well with statusCode 200.  
What could have gone wrong?

---

<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:57pm UTC](https://discourse.sst.dev/t/add-a-get-note-api/132/12 "2018-05-09T19:57:39Z")

</div>

_From @jayair on Mon Jun 12 2017 17:27:46 GMT+0000 (UTC)_  
  
@idowolf The get function uses the `id` from the note you created in the Create chapter. So make sure to replace this [https://github.com/AnomalyInnovations/serverless-stack-demo-api/blob/add-a-get-note-api/mocks/get-event.json#L3](https://github.com/AnomalyInnovations/serverless-stack-demo-api/blob/add-a-get-note-api/mocks/get-event.json#L3) with the one you get when you run the `create` 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:57pm UTC](https://discourse.sst.dev/t/add-a-get-note-api/132/13 "2018-05-09T19:57:39Z")

</div>

_From @yashg5 on Fri Jul 28 2017 13:04:07 GMT+0000 (UTC)_  
  
How come item not found will be status code 500. i think there has to be another way to respond with proper status codes like 400, 404

---

<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:57pm UTC](https://discourse.sst.dev/t/add-a-get-note-api/132/14 "2018-05-09T19:57:40Z")

</div>

_From @jayair on Fri Jul 28 2017 17:25:59 GMT+0000 (UTC)_  
  
@yashg5 Yeah we leave that to you. It’s pretty straightforward, the status codes are being set here - [https://github.com/AnomalyInnovations/serverless-stack-demo-api/blob/master/libs/response-lib.js#L6](https://github.com/AnomalyInnovations/serverless-stack-demo-api/blob/master/libs/response-lib.js#L6)

---

<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:57pm UTC](https://discourse.sst.dev/t/add-a-get-note-api/132/15 "2018-05-09T19:57:40Z")

</div>

_From @sdooley-ebsco on Thu Nov 09 2017 14:01:19 GMT+0000 (UTC)_  
  
When running…

```auto
serverless invoke local --function get --path mocks/get-event.json

```

I get the following type error “lambda is not a function”. Any thoughts on what is causing this problem?

---

<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:57pm UTC](https://discourse.sst.dev/t/add-a-get-note-api/132/16 "2018-05-09T19:57:40Z")

</div>

_From @jayair on Thu Nov 09 2017 18:54:38 GMT+0000 (UTC)_  
  
@sdooley-ebsco It might be because `get` is probably not pointing to a function? It’s most likely a typo in your `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:57pm UTC](https://discourse.sst.dev/t/add-a-get-note-api/132/17 "2018-05-09T19:57:40Z")

</div>

_From @omairhamid on Sun Dec 31 2017 01:15:36 GMT+0000 (UTC)_  
  
In “get.js”, these are the first two lines:  
`import * as dynamoDbLib from "./libs/dynamodb-lib";`  
`import { success, failure } from "./libs/response-lib";`

I thought I had installed my AWS CLI and other tools correctly, but when I run my /mocks/get-event.json, I get the following error:

> ERROR in ./get.js  
> Module not found: Error: Can’t resolve ‘./libs/dynamodb-lib’ in ‘/notes-app-api’  
> @ ./get.js 68:19-49

> ERROR in ./get.js  
> Module not found: Error: Can’t resolve ‘./libs/response-lib’ in ‘/notes-app-api’  
> @ ./get.js 72:19-49

Where should it be finding /libs/response-lib and /libs/dynamodb-lib on my macOS, so that I can update the paths in get.js accordingly?

Thank you

---

<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:57pm UTC](https://discourse.sst.dev/t/add-a-get-note-api/132/18 "2018-05-09T19:57:41Z")

</div>

_From @jayair on Sun Dec 31 2017 04:06:33 GMT+0000 (UTC)_  
  
@omairhamid We create both of these in the previous chapter here - [https://serverless-stack.com/chapters/add-a-create-note-api.html#refactor-our-code](https://serverless-stack.com/chapters/add-a-create-note-api.html#refactor-our-code)

---

<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:57pm UTC](https://discourse.sst.dev/t/add-a-get-note-api/132/19 "2018-05-09T19:57:41Z")

</div>

_From @omairhamid on Sun Dec 31 2017 14:30:13 GMT+0000 (UTC)_  
  
@jayair Thank you. I have no idea how I missed that. Happy new year!

---

<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:57pm UTC](https://discourse.sst.dev/t/add-a-get-note-api/132/20 "2018-05-09T19:57:41Z")

</div>

_From @starkos on Thu Jan 25 2018 01:04:45 GMT+0000 (UTC)_  
  
When running…

```
serverless invoke local --function get --path mocks/get-event.json

```

I get the error…

```
 Unexpected token u in JSON at position 0

```

Which appears related to [this SO question](https://stackoverflow.com/questions/43959961/serverless-lambda-function-throwing-error-when-trying-to-insert-data-into-dynamo). Adding…

```
"body": "{\"text\":\"\"}"

```

…to `get-event.json` fixed it.

[Next page](https://discourse.sst.dev/t/add-a-get-note-api/132.md?page=2)
