# Add a Create Note API

**URL:** <https://discourse.sst.dev/t/add-a-create-note-api/125>\
**Category:** Chapter Comments\
**Created:** [May 9, 2018, 7:44pm UTC](https://discourse.sst.dev/t/add-a-create-note-api/125 "2018-05-09T19:44:26Z")\
**Posts on this page:** 12\
**Page:** 13

<div class="post-metadata">

**Author:** ![huntzinger92](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/huntzinger92/32/1039_2.png) [@huntzinger92](https://discourse.sst.dev/u/huntzinger92)\
**Post date:** [November 25, 2020, 4:23pm UTC](https://discourse.sst.dev/t/add-a-create-note-api/125/249 "2020-11-25T16:23:29Z")

</div>

Like some other people here, I’m also getting a “Requested resource not found” error when running $ serverless invoke local --function create --path mocks/create-event.json

I’m not getting a code error, though. I get the caught exception from create.js:

```auto
{
    "statusCode": 500,
    "body": "{\"error\":\"Requested resource not found\"}"
}

```

With some console.logs, I’ve confirmed that my create.js file is receiving the create-event.json data correctly. I’ve also double-checked that my “notes” table actually exists, which I saw was an issue for some people. I feel like I might be missing something simple. Any ideas?

Edit: I figured it out. Apparently, you may need to manually set your AWS region, even if you’ve used all default options throughout the tutorial. In my case, I fixed the issue with the following code:

```auto
AWS.config.update({ region: "us-east-2" });

```

According to [AWS’s docs](https://docs.aws.amazon.com/emr/latest/ManagementGuide/emr-plan-region.html), us-east-2 is the default region for accounts made after May 17, 2017.

---

<div class="post-metadata">

**Author:** ![Equintana](https://avatars.discourse-cdn.com/v4/letter/e/ebca7d/32.png) [@Equintana](https://discourse.sst.dev/u/Equintana)\
**Post date:** [December 29, 2020, 5:26am UTC](https://discourse.sst.dev/t/add-a-create-note-api/125/251 "2020-12-29T05:26:50Z")

</div>

When I run `serverless invoke local --function create --path mocks/create-event.json` in my terminal I am not getting back any type of results at all. No errors or anything. My code is matching the code from the tutorial other than my arn is using us-east-2 instead of us-east-1. Has anyone run into this as well? See my code below:

create.js

```
import * as uuid from "uuid";

import AWS from "aws-sdk";

const dynamoDb = new AWS.DynamoDB.DocumentClient();

export async function main(event, context) {

    // Request body is passed in as a JSON encoded string in 'event.body'

    const data = JSON.parse(event.body);

    const params = {

        TableName: process.env.tableName,

        Item: {

            // The attributes of the item to be created

            userId: "123", // The id of the author

            noteId: uuid.v1(), // A unique uuid

            content: data.content, // Parsed from request body

            attachment: data.attachment, // Parsed from request body

            createdAt: Date.now(), // Current Unix timestamp

        },

    };

    try {

        await dynamoDb.put(params).promise();

        return {

            statusCode: 200,

            body: JSON.stringify(params.Item),

        };

    } catch (e) {

        return {

            statusCode: 500,

            body: JSON.stringify({ error: e.message }),

        };

    }

}

```

serverles.yml

```
service: notes-api

# Create an optimized package for our functions

package:

  individually: true

plugins:

  - serverless-bundle # Package our functions with Webpack

  - serverless-offline

  - serverless-dotenv-plugin # Load .env as environment variables

provider:

  name: aws

  runtime: nodejs12.x

  stage: prod

  region: us-east-2

  # These environment variables are made available to our functions

  # under process.env.

  environment:

    tableName: notes

  # 'iamRoleStatements' defines the permission policy for the Lambda function.

  # In this case Lambda functions are granted with permissions to access DynamoDB.

  iamRoleStatements:

    - Effect: Allow

      Action:

        - dynamodb:Scan

        - dynamodb:Query

        - dynamodb:GetItem

        - dynamodb:PutItem

        - dynamodb:UpdateItem

        - dynamodb:DeleteItem

        - dynamodb:DescribeTable

      Resource: "arn:aws:dynamodb:us-east-2:*:*"

functions:

  # Defines an HTTP API endpoint that calls the main function in create.js

  # - path: url path is /notes

  # - method: POST request

  create:

    handler: create.main

    events:

      - http:

          path: notes

          method: post

```

create-event.json

```
{

    "body": "{\"content\":\"hello world\",\"attachment\":\"hello.jpg\"}"

}
```

---

<div class="post-metadata">

**Author:** ![michaelbannon123](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/michaelbannon123/32/1074_2.png) [@michaelbannon123](https://discourse.sst.dev/u/michaelbannon123)\
**Post date:** [December 29, 2020, 5:57pm UTC](https://discourse.sst.dev/t/add-a-create-note-api/125/252 "2020-12-29T17:57:05Z")

</div>

Where did you put that line of code into, I’m receiving errors when I try to implement it.

---

<div class="post-metadata">

**Author:** ![michaelbannon123](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/michaelbannon123/32/1074_2.png) [@michaelbannon123](https://discourse.sst.dev/u/michaelbannon123)\
**Post date:** [December 29, 2020, 6:02pm UTC](https://discourse.sst.dev/t/add-a-create-note-api/125/253 "2020-12-29T18:02:34Z")

</div>

When I run the command below I receive this error

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

```

```auto
Serverless: Deprecation warning: Detected ".env" files. Note that Framework now supports loading variables from those files when "useDotenv: true" is set (and that will be the default
from next major release)
            More Info: https://www.serverless.com/framework/docs/deprecations/#LOAD_VARIABLES_FROM_ENV_FILES
Serverless: DOTENV: Loading environment variables from .env:
Serverless: - tableName
Serverless: Deprecation warning: Starting with next major version, API Gateway naming will be changed from "{stage}-{service}" to "{service}-{stage}".
            Set "provider.apiGateway.shouldStartNameWithService" to "true" to adapt to the new behavior now.
            More Info: https://www.serverless.com/framework/docs/deprecations/#AWS_API_GATEWAY_NAME_STARTING_WITH_SERVICE
Serverless: Bundling with Webpack...
{
    "statusCode": 500,
    "body": "{\"error\":\"One or more parameter values were invalid: Missing the key userid in the item\"}"
}

```

I have checked and as far as I can see everything lines up with my code, my code from the create.js file for the item is as follows

```auto
export const main = handler(async (event, context) => {
    const data = JSON.parse(event.body);
    const params = {
        TableName: process.env.tableName,
        Item: {
            // The attributes of the item to be created
            userId: "123", // The id of the author
            noteId: uuid.v1(), // A unique uuid
            content: data.content, // Parsed from request body
            attachment: data.attachment, // Parsed from request body
            createdAt: Date.now(), // Current Unix timestamp
        },
    };

```

---

<div class="post-metadata">

**Author:** ![markgargan](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/markgargan/32/903_2.png) [@markgargan](https://discourse.sst.dev/u/markgargan)\
**Post date:** [December 30, 2020, 1:00pm UTC](https://discourse.sst.dev/t/add-a-create-note-api/125/254 "2020-12-30T13:00:02Z")

</div>

Hi @jayair, I’m following the companion epub guide v5.0.1 and the content of the create.js and create-event.json are different and contain more information? Would you know which one is the most uptodate?

Also I ran the serverless command in the mocks directory by accident and the command exited silently. Would have throught it would’ve complained that it couldn’t find the file denoted by the --path.

Thanks,  
Mark.

---

<div class="post-metadata">

**Author:** ![markgargan](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/markgargan/32/903_2.png) [@markgargan](https://discourse.sst.dev/u/markgargan)\
**Post date:** [December 30, 2020, 1:33pm UTC](https://discourse.sst.dev/t/add-a-create-note-api/125/255 "2020-12-30T13:33:17Z")

</div>

Hi @jayair, sorry now I spoke too soon, the companion updated the version of the create.js later in the chapter!

thanks,  
Mark.

---

<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:** [January 3, 2021, 1:13am UTC](https://discourse.sst.dev/t/add-a-create-note-api/125/256 "2021-01-03T01:13:03Z")

</div>

You’ll need to set this at the top of your Lambda functions. Below the AWS import.

---

<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:** [January 3, 2021, 1:13am UTC](https://discourse.sst.dev/t/add-a-create-note-api/125/257 "2021-01-03T01:13:57Z")

</div>

Try running this command instead:

```auto
SLS_DEBUG=* serverless invoke local --function create --path mocks/create-event.json

```

---

<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:** [January 3, 2021, 1:14am UTC](https://discourse.sst.dev/t/add-a-create-note-api/125/258 "2021-01-03T01:14:52Z")

</div>

It might be that your tables have `userid` as the column but your code is using `userId`. Make sure the case is set correctly.

---

<div class="post-metadata">

**Author:** ![Equintana](https://avatars.discourse-cdn.com/v4/letter/e/ebca7d/32.png) [@Equintana](https://discourse.sst.dev/u/Equintana)\
**Post date:** [January 5, 2021, 6:20pm UTC](https://discourse.sst.dev/t/add-a-create-note-api/125/259 "2021-01-05T18:20:44Z")

</div>

I tried the command and I get this:

![image](https://canada1.discourse-cdn.com/flex032/uploads/serverless_stack/original/2X/a/afba34e6248e5caa449957efad044f058ca7cfbb.png)

I tried adding it to my system environment variables manually since I’m on Windows 10. I also tried running `$Env:SLS_DEBUG='true'`

Then when I ran `serverless invoke local --function create --path mocks/create-event.json` I get this:

```auto
PS C:\Users\eduardoq\Desktop\Projects\React-Projects\serverles-stack> serverless invoke local --function create --path mocks/create-event.json
Serverless: Load command interactiveCli
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command create
Serverless: Load command install
Serverless: Load command package
Serverless: Load command deploy
Serverless: Load command deploy:function
Serverless: Load command deploy:list
Serverless: Load command deploy:list:functions
Serverless: Load command invoke
Serverless: Load command invoke:local
Serverless: Load command info
Serverless: Load command logs
Serverless: Load command metrics
Serverless: Load command print
Serverless: Load command remove
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command slstats
Serverless: Load command plugin
Serverless: Load command plugin
Serverless: Load command plugin:install
Serverless: Load command plugin
Serverless: Load command plugin:uninstall
Serverless: Load command plugin
Serverless: Load command plugin:list
Serverless: Load command plugin
Serverless: Load command plugin:search
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command upgrade
Serverless: Load command uninstall
Serverless: Load command login
Serverless: Load command logout
Serverless: Load command generate-event
Serverless: Load command test
Serverless: Load command dashboard
Serverless: Load command output
Serverless: Load command output:get
Serverless: Load command output:list
Serverless: Load command param
Serverless: Load command param:get
Serverless: Load command param:list
Serverless: Load command studio
Serverless: Invoke invoke:local

```

---

<div class="post-metadata">

**Author:** ![Equintana](https://avatars.discourse-cdn.com/v4/letter/e/ebca7d/32.png) [@Equintana](https://discourse.sst.dev/u/Equintana)\
**Post date:** [February 5, 2021, 6:03am UTC](https://discourse.sst.dev/t/add-a-create-note-api/125/260 "2021-02-05T06:03:28Z")

</div>

Has anyone else ran into the issue I posted back on Jan 5th? I haven’t been able to figure out what’s going on. I tried looking online for other resources but haven’t found much. I have already tried uninstalling and reinstalling the serverless package, as well as downgrading serverless version but neither of them worked. If anyone has ran into this and found a solution, I would greatly appreciate your input.

---

<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, 2021, 8:35pm UTC](https://discourse.sst.dev/t/add-a-create-note-api/125/261 "2021-05-15T20:35:50Z")

</div>

What’s the actual error you are getting?

[Previous page](https://discourse.sst.dev/t/add-a-create-note-api/125.md?page=12)
