nervous-systems / serverless-cljs-plugin

Serverless plugin for Clojurescript deployment w/ cljs-lambda
The Unlicense
75 stars 10 forks source link

Serveless invoke local does not work #3

Closed arichiardi closed 7 years ago

arichiardi commented 7 years ago

Hello folks!

I am trying to invoke a function locally:

After having executed serverless package to create my zip file:

$ serverless package
Serverless: Targeting /home/arichiardi/git/logpoc/.serverless/logpoc.zip
Serverless: Packaging service...
Serverless: Executing "lein update-in :cljs-lambda assoc :functions '[{:name "logpoc-dev-bunyan-lambda" :invoke logpoc.core/bunyan-lambda}]' -- cljs-lambda build :output /home/arichiardi/git/logpoc/.serverless/logpoc.zip :quiet"
Serverless: Returning artifact path /home/arichiardi/git/logpoc/.serverless/logpoc.zip

I try the following, which fails:

$ serverless invoke local -f bunyan-lambda
Serverless: Targeting /home/arichiardi/git/logpoc/.serverless/bunyan-lambda.zip
{ Error: Cannot find module './/goog/bootstrap/nodejs.js'
    at Function.Module._resolveFilename (module.js:485:15)
    at Function.Module._load (module.js:437:25)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/arichiardi/git/logpoc/index.js:2:1)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at AwsInvokeLocal.invokeLocalNodeJs (/home/arichiardi/.nvm/versions/node/v8.1.3/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:156:33)
    at AwsInvokeLocal.invokeLocal (/home/arichiardi/.nvm/versions/node/v8.1.3/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:114:19)
    at AwsInvokeLocal.tryCatcher (/home/arichiardi/.nvm/versions/node/v8.1.3/lib/node_modules/serverless/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/home/arichiardi/.nvm/versions/node/v8.1.3/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/home/arichiardi/.nvm/versions/node/v8.1.3/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/home/arichiardi/.nvm/versions/node/v8.1.3/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/home/arichiardi/.nvm/versions/node/v8.1.3/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:693:18)
    at Async._drainQueue (/home/arichiardi/.nvm/versions/node/v8.1.3/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:133:16)
    at Async._drainQueues (/home/arichiardi/.nvm/versions/node/v8.1.3/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:143:10)
    at Immediate.Async.drainQueues (/home/arichiardi/.nvm/versions/node/v8.1.3/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:800:20)
    at tryOnImmediate (timers.js:762:5)
    at processImmediate [as _immediateCallback] (timers.js:733:5) code: 'MODULE_NOT_FOUND' }

Am I doing something wrong here?

Thank you this package is really great for mixed cljs/js project on AWS Lambda!

arichiardi commented 7 years ago

It looks like the Typescript plugin handles the invoke local in a custom way: https://github.com/graphcool/serverless-plugin-typescript/blob/master/src/index.ts#L43-L57

moea commented 7 years ago

@arichiardi Hi!

You're not doing anything wrong, I don't think - I didn't include specific support for this, and haven't looked at what it would take - it may be relatively simple. If it's something you want to take a look at, that'd be great, too.

arichiardi commented 7 years ago

Yeah well, I have many OSS things queued up but I will try to explore a solution...whoever comes first wins ah ah!

arichiardi commented 7 years ago

So the problem is that invoke local -f example does not pass a service.service value, and therefore basepath takes opts.function...

arichiardi commented 7 years ago

Second problem is that we produce a zip and remove the js files...so this is probably not worth pursuing given the REPL...

arichiardi commented 7 years ago

So it seems that having index.js in the project root also enable sls invoke local --function to work properly (at least here). Closing this!