Add a Create Note API

Your first error is usually related to your serverless.yml, make sure it is properly formatted.

For the second error, make sure this line is at the top of your config const slsw = require("serverless-webpack");. The entries object comes from that.

Hello Jayair and thanks for your reply. For the second hint: I’ve the exact line in my config. I assume my first error is maye driven by the second, since I can’t deploay anything because of that?

Any other idea why I keep getting this error message?

For all the people having problems with credentials:

In create.js add:

import credentials from "./credentials.json"

AWS.config.credentials = credentials;

Add additional file credentials.json

{ "accessKeyId": "aaa", "secretAccessKey": "bbb", "region": "us-east-1" }

I am having an issue where the serverless invoke local command returns empty (not any error code, just returns a command prompt on the next line). I’ve completely reinstalled NPM and Serverless, and reinstalled the starter package to get back to a blank slate with no luck. I noticed that the files default to reference an earlier version of node (8.10) so after getting an empty result from the serverless invoke local command, I tried updating the serverless.yaml and the babelrc file to reference node 8.11.4. I still get an empty response running the invoke local command.

I’m sort of a loss now, with no real next step to fix this. Anyone have any idea of where I can start trouble shooting this?

I’m actually not sure what the issue is. Was it working for you before and it stopped working?

Which version of Node are you using on your machine? And do any serverless commands work for you?

Hi everyone i keep getting this error when i invoke the function , i have double checked my credentials and all is well but for some reason i keep getting this error

Hi everyone i keep getting this error when i invoke the function , i have double checked my credentials and all is well but for some reason i keep getting this error

$ AWS_PROFILE=user1 serverless invoke local --function create --path mocks/create-event.json
Serverless: Bundling with Webpack...
Time: 1011ms
Built at: 07/03/2019 4:55:42 PM
        Asset      Size  Chunks             Chunk Names
    create.js  7.16 KiB  create  [emitted]  create
create.js.map  6.98 KiB  create  [emitted]  create
Entrypoint create = create.js create.js.map
[./create.js] 2.08 KiB {create} [built]
[aws-sdk] external "aws-sdk" 42 bytes {create} [built]
[babel-runtime/core-js/json/stringify] external "babel-runtime/core-js/json/stringify" 42 bytes {create} [built]
[source-map-support/register] external "source-map-support/register" 42 bytes {create} [built]
[uuid] external "uuid" 42 bytes {create} [built]
{
    "statusCode": 500,
    "headers": {
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Credentials": true
    },
    "body": "{\"status\":false}"
}

I am getting error when running ‘AWS_PROFILE’ is not recognised when I run AWS_PROFIKE=myProfile serverless invoke local --function create --path mocks/create-event.json

The status: false response is sent by our code. So you could simply add a console.log in your code to debug which line is causing the error.

Are you running this on Windows?

I get this error

$ serverless invoke local --function create --path mocks/create-event.json
Serverless: Bundling with Webpack...

ERROR in /home/peter/notes-serverless-app/notes-app-api/create.js
Module build failed (from ../node_modules/babel-loader/lib/index.js):
Error: Plugin/Preset files are not allowed to export objects, only functions. In /home/peter/notes- 
serverless-app/notes-app-api/node_modules/babel-preset-stage-3/lib/index.js
...
Unhandled rejection Error: Webpack compilation error, see above

I am getting the same result, the command line just return nothing. I have the version information like this. Besides, I cannot find the aws folder with config file and credential file in it. I do exactly the same as the tutorial.

This is my project directory along with my serverless.yml. I’ve changed the region to the right one with my dynamo so that shouldn’t be a problem.

Never mind, I solve the problems. My mocks, libs and create.js are in wrong folder. However I do notice that in create.js, item’s fields are not exactly like the ones in tutorial. It should be ‘userid’ and ‘noteid’ instead of ‘userId’ and ‘noteId’

Otherwise you will get a validation exception!

Hmm that looks like an older version of the tutorial? Some of the babel presets in that error are pretty old.

Hmm those depend on what was set while creating the table. We use camel case throughout the tutorial.

I was wondering why do we use PUT in order to create entry in Dynamo. Why did not we use POST? Do they differ ?

As far as I know, generally, we use POST for creating new entries, and for the PUT to update the existing entries.

If you are referring to HTTP POST vs PUT that doesn’t apply to DynamoDB. We use the put method in the DynamoDB Client SDK - https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html#put-property.

Hi, using windows. No idea what i’ve done wrong, i’ve just copied and pasted for the most part, can you please assist:

PS D:\Shadow\Desktop\notes-app-api> serverless invoke local --function create --path mocks/create-event.json

  Syntax Error -------------------------------------------

  D:\Shadow\Desktop\notes-app-api\node_modules\serverless-offline\src\ServerlessOffline.js:157
      );
      ^

  SyntaxError: Unexpected token )
      at createScript (vm.js:56:10)
      at Object.runInThisContext (vm.js:97:10)
      at Module._compile (module.js:542:28)
      at Object.Module._extensions..js (module.js:579:10)
      at Module.load (module.js:487:32)
      at tryModuleLoad (module.js:446:12)
      at Function.Module._load (module.js:438:3)
      at Module.require (module.js:497:17)
      at require (internal/module.js:20:19)
      at Object.<anonymous> (D:\Shadow\Desktop\notes-app-api\node_modules\serverless-offline\src\index.js:3:18)
      at Module._compile (module.js:570:32)
      at Object.Module._extensions..js (module.js:579:10)
      at Module.load (module.js:487:32)
      at tryModuleLoad (module.js:446:12)
      at Function.Module._load (module.js:438:3)
      at Module.require (module.js:497:17)
      at require (internal/module.js:20:19)
      at plugins.forEach.error (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\lib\classes\PluginManager.js:107:18)
      at Array.forEach (native)
      at PluginManager.loadPlugins (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\lib\classes\PluginManager.js:102:13)
      at PluginManager.loadServicePlugins (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\lib\classes\PluginManager.js:147:10)
      at PluginManager.loadAllPlugins (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\lib\classes\PluginManager.js:97:10)
      at pluginManager.loadConfigFile.then.then (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\lib\Serverless.js:78:35)
      at tryCatcher (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\util.js:16:23)
      at Promise._settlePromiseFromHandler (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:517:31)
      at Promise._settlePromise (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:574:18)
      at Promise._settlePromise0 (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:619:10)
      at Promise._settlePromises (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:699:18)
      at Promise._fulfill (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:643:18)
      at Promise._resolveCallback (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:437:57)
      at Promise._settlePromiseFromHandler (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:529:17)
      at Promise._settlePromise (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:574:18)
      at Promise._settlePromise0 (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:619:10)
      at Promise._settlePromises (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:699:18)
      at Promise._fulfill (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:643:18)
      at PromiseArray._resolve (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise_array.js:126:19)
      at PromiseArray._promiseFulfilled (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise_array.js:144:14)
      at Promise._settlePromise (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:579:26)
      at Promise._settlePromise0 (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:619:10)
      at Promise._settlePromises (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:699:18)
      at Promise._fulfill (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:643:18)
      at Promise._resolveCallback (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:437:57)
      at Promise._settlePromiseFromHandler (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:529:17)
      at Promise._settlePromise (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:574:18)
      at Promise._settlePromise0 (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:619:10)
      at Promise._settlePromises (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:699:18)
      at Promise._fulfill (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:643:18)
      at PropertiesPromiseArray.PromiseArray._resolve (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise_array.js:126:19)
      at PropertiesPromiseArray._promiseFulfilled (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\props.js:78:14)
      at Promise._settlePromise (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:579:26)
      at Promise._settlePromise0 (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:619:10)
      at Promise._settlePromises (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:699:18)
      at Promise._fulfill (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:643:18)
      at Promise._resolveCallback (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:437:57)
      at Promise._settlePromiseFromHandler (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:529:17)
      at Promise._settlePromise (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:574:18)
      at Promise._settlePromise0 (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:619:10)
      at Promise._settlePromises (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:695:18)
      at _drainQueueStep (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\async.js:138:12)
      at _drainQueue (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\async.js:131:9)
      at Async._drainQueues (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\async.js:147:5)
      at Immediate.Async.drainQueues (C:\Users\Shadow\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\async.js:17:14)
      at runCallback (timers.js:672:20)
      at tryOnImmediate (timers.js:645:5)
      at processImmediate [as _immediateCallback] (timers.js:617:5)

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

  Get Support --------------------------------------------
     Docs:          docs(dot)serverless(dot)com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com

  Your Environment Information ---------------------------
     Operating System:          win32
     Node Version:              6.11.2
     Framework Version:         1.52.0
     Plugin Version:            2.0.0
     SDK Version:               2.1.1

Seems my node version was simply too old, updated and now fixed. Maybe a warning of the minimum node could be checked too?

So it is working now after you updated your Node version?