Add a Create Note API


#21

From @martinsaporiti on Sun May 21 2017 11:50:29 GMT+0000 (UTC)

Hi, everyone. I need your help, please!!!

When I running serverless webpack invoke --function create --path event.json the result is this:

	**import _JSON$stringify from 'babel-runtime/core-js/json/stringify';**
	^^^^^^
SyntaxError: Unexpected token import
    at Object.exports.runInThisContext (vm.js:76:16)
    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 ServerlessWebpack.loadHandler (/Users/sapo/Development/notes/notes-app-api/node_modules/serverless-webpack/lib/run.js:21:20)
    at ServerlessWebpack.run (/Users/sapo/Development/notes/notes-app-api/node_modules/serverless-webpack/lib/run.js:61:26)
    at ServerlessWebpack.tryCatcher (/Users/sapo/Development/notes/notes-app-api/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/sapo/Development/notes/notes-app-api/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/Users/sapo/Development/notes/notes-app-api/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/Users/sapo/Development/notes/notes-app-api/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/Users/sapo/Development/notes/notes-app-api/node_modules/bluebird/js/release/promise.js:693:18)
    at Promise._fulfill (/Users/sapo/Development/notes/notes-app-api/node_modules/bluebird/js/release/promise.js:638:18)
    at Promise._resolveCallback (/Users/sapo/Development/notes/notes-app-api/node_modules/bluebird/js/release/promise.js:432:57)
    at Promise._settlePromiseFromHandler (/Users/sapo/Development/notes/notes-app-api/node_modules/bluebird/js/release/promise.js:524:17)
    at Promise._settlePromise (/Users/sapo/Development/notes/notes-app-api/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/Users/sapo/Development/notes/notes-app-api/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/Users/sapo/Development/notes/notes-app-api/node_modules/bluebird/js/release/promise.js:693:18)
    at Promise._fulfill (/Users/sapo/Development/notes/notes-app-api/node_modules/bluebird/js/release/promise.js:638:18)
From previous event:
    at PluginManager.invoke (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:234:22)
    at PluginManager.run (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:253:17)
    at variables.populateService.then (/usr/local/lib/node_modules/serverless/lib/Serverless.js:96:33)
From previous event:
    at Serverless.run (/usr/local/lib/node_modules/serverless/lib/Serverless.js:87:74)
    at serverless.init.then (/usr/local/lib/node_modules/serverless/bin/serverless:23:50)

  Your Environment Information -----------------------------
     OS:                 darwin
     Node Version:       6.9.4
     Serverless Version: 1.13.2

Thanks!!!


#22

From @jayair on Sun May 21 2017 19:07:48 GMT+0000 (UTC)

@go4cas That’s weird, the react-app preset should handle that already. Can I see your package.json just to make sure things are okay?


#23

From @jayair on Sun May 21 2017 19:09:10 GMT+0000 (UTC)

@martinsaporiti this looks like the same issue as @go4cas. Let me check what is going on.


#24

From @jayair on Sun May 21 2017 20:19:33 GMT+0000 (UTC)

@martinsaporiti @go4cas You guys are right, there is an issue with the new react-app preset. I just updated the chapter with the proper presets - https://github.com/AnomalyInnovations/serverless-stack-com/commit/201c8818686650b67008d108b0aef047d8a59cec


#25

From @martinsaporiti on Mon May 22 2017 02:15:26 GMT+0000 (UTC)

Thanks @jayair and @go4cas ! Now work perfectly:

{ statusCode: 200,
  headers: 
   { 'Access-Control-Allow-Origin': '*',
     'Access-Control-Allow-Credentials': true },
  body: '{"userId":"USER-SUB-1234","noteId":"b605af70-3e93-11e7-8117-312305557adf","content":"hello world","attachment":"hello.jpg","createdAt":1495418979303}' }

I will continue with the tutorial. It’s very useful.
Thanks again!


#26

From @oliv9286 on Fri Jun 02 2017 21:01:20 GMT+0000 (UTC)

@jayair I’m running into the same problem as @deivers and @vfonsecapv when I run the test with event.json. I do have multiple profiles and I’m not using the default profile in this case. I’m using us-west-2 and I believe I already changed that everywhere in the code. Any clue how I can debug?


#27

From @oliv9286 on Fri Jun 02 2017 21:23:14 GMT+0000 (UTC)

nevermind, I figured it out. If you’re not using your default profile then in your create.js you need to do
const credentials = new AWS.SharedIniFileCredentials({profile: 'profile_name'}); AWS.config.credentials = credentials;


#28

From @jayair on Sat Jun 03 2017 11:46:36 GMT+0000 (UTC)

@oliv9286 Thanks for reporting back. Are you setting this in the top of your create.js?


#29

From @tobyjo on Mon Jun 05 2017 15:27:48 GMT+0000 (UTC)

I also get the same error as @deivers and @vfonsecapv .

When I run

./node_modules/serverless/bin/serverless webpack invoke --function create --path event.json

I get

Serverless: Run function create...
{ ResourceNotFoundException: Requested resource not found
    at Request.extractError (/home/tjones/note-app-api/node_modules/aws-sdk/lib/protocol/json.js:48:27)
    at Request.callListeners (/home/tjones/note-app-api/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
    at Request.emit (/home/tjones/note-app-api/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
    at Request.emit (/home/tjones/note-app-api/node_modules/aws-sdk/lib/request.js:682:14)
    at Request.transition (/home/tjones/note-app-api/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/home/tjones/note-app-api/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /home/tjones/note-app-api/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/home/tjones/note-app-api/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/home/tjones/note-app-api/node_modules/aws-sdk/lib/request.js:684:12)
    at Request.callListeners (/home/tjones/note-app-api/node_modules/aws-sdk/lib/sequential_executor.js:115:18)
    at Request.emit (/home/tjones/note-app-api/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
    at Request.emit (/home/tjones/note-app-api/node_modules/aws-sdk/lib/request.js:682:14)
    at Request.transition (/home/tjones/note-app-api/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/home/tjones/note-app-api/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /home/tjones/note-app-api/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/home/tjones/note-app-api/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/home/tjones/note-app-api/node_modules/aws-sdk/lib/request.js:684:12)
    at Request.callListeners (/home/tjones/note-app-api/node_modules/aws-sdk/lib/sequential_executor.js:115:18)
    at callNextListener (/home/tjones/note-app-api/node_modules/aws-sdk/lib/sequential_executor.js:95:12)
    at IncomingMessage.onEnd (/home/tjones/note-app-api/node_modules/aws-sdk/lib/event_listeners.js:256:13)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:185:7)
  message: 'Requested resource not found',
  code: 'ResourceNotFoundException',

Note that I didnt install the serverless module as global.
I do not have multiple profiles as @oliv9286 did.


#30

From @fwang on Wed Jun 07 2017 15:35:18 GMT+0000 (UTC)

@tobyjo can I take a look at your serverless.yml?


#31

From @tobyjo on Thu Jun 08 2017 09:27:53 GMT+0000 (UTC)

@fwang Sure, please find attached.
serverless.zip


#32

From @kevinnguy on Sat Jun 10 2017 05:56:13 GMT+0000 (UTC)

@tobyjo I’ve had the same issue as you and my problem was that my DynamoDB table wasn’t created when I thought I did. I would double-check in your AWS Console and see if your notes table was created.


#33

From @fwang on Sat Jun 10 2017 15:12:04 GMT+0000 (UTC)

@tobyjo A side note about your serverless.yml, this is not related to the error you are seeing. The authorizer arn in your serverless.yml should start with “arn:aws:cognito-idp:” and look something like " arn:aws:cognito-idp:us-east-1:232771856781:userpool/us-east-1_YExxXXxxx". You can get the User Pool arn from this chapter:

Back to the issue you were seeing, try @kevinnguy’s suggestion.


#34

From @tobyjo on Fri Jun 16 2017 13:51:30 GMT+0000 (UTC)

@kevinnguy @fwang Thanks both. Have been distracted currently with other work but as soon as I get back to this I will let you know the results. Thanks again.


#35

From @copperspeed on Fri Jun 23 2017 07:53:35 GMT+0000 (UTC)

Any reason why I am receiving the error below?

serverless webpack invoke -f create -p mocks/create-event.json
/mnt/c/Users/cgrecea/AppData/Roaming/npm/node_modules/serverless/node_modules/bluebird/js/release/async.js:48
        fn = function () { throw arg; };
                           ^

ServerlessError: In the command you just typed, the "webpack" is valid but "invoke" is not.  Enter "serverless help" to see the actions for this context.
    at new ServerlessError (/mnt/c/Users/cgrecea/AppData/Roaming/npm/node_modules/serverless/lib/ServerlessError.js:17:11)

#36

From @jayair on Fri Jun 23 2017 17:11:22 GMT+0000 (UTC)

@copperspeed Can you make sure you’ve added serverless-webpack to your project? We do this in the Install Babel and Webpack step of this chapter http://serverless-stack.com/chapters/add-support-for-es6-es7-javascript.html.


#37

From @copperspeed on Sat Jun 24 2017 01:33:26 GMT+0000 (UTC)

@jayair yes, I have serverless-webpack installed.

devDependencies": {
    "aws-sdk": "^2.72.0",
    "babel-core": "^6.25.0",
    "babel-loader": "^7.0.0",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-stage-3": "^6.24.1",
    "glob": "^7.1.2",
    "serverless-webpack": "^1.0.0-rc.4",
    "webpack": "^2.6.1",
    "webpack-node-externals": "^1.6.0"
  },
  "dependencies": {
    "babel-runtime": "^6.23.0",
    "uuid": "^3.1.0"
  }

#38

From @copperspeed on Sat Jun 24 2017 21:58:33 GMT+0000 (UTC)

Ok, my issue was do to forgetting to install Serverless. Duh!!! lol


#39

From @RobbingDaHood on Tue Jul 04 2017 17:11:49 GMT+0000 (UTC)

This weekend I got through the whole example without any problems, today I get the error:

ERROR in Entry module not found: Error: Can’t resolve ‘babel’ in ‘C:\projects\happyToHelp\backend’
BREAKING CHANGE: It’s no longer allowed to omit the ‘-loader’ suffix when using loaders.
You need to specify ‘babel-loader’ instead of ‘babel’,
see https://webpack.js.org/guides/migrating/#automatic-loader-module-name-extension-removed

When executing:
serverless webpack invoke --function create --path mocks/create-event.json

I fixed this by going to webpack.config.js and changing from:
loaders: [‘babel’],
To:
loaders: [‘babel-loader’],

And now it works.


#40

From @jayair on Tue Jul 04 2017 17:27:08 GMT+0000 (UTC)

@RobbingDaHood Thanks for letting us know. I’ll take a look into whats going on. Can you share your package.json? I’d like to see which version is giving this error.