serverless-heaven / serverless-webpack

Serverless plugin to bundle your lambdas with Webpack

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Single function deploy does not invoke the plugin

HyperBrain opened this issue · comments

I do not know if this is a problem with Serverless' lifecycle events or if it is a problem within the webpack plugin. If I try to upload a single function during development, using serverless deploy function -f auth the webpack build is not triggered and Serverless tries to upload the whole project which exceeds the upload file size limit of 70MB.

When deploying the complete service with serverless deploy the plugin is invoked correctly and the resulting function code ZIP is about 17MB.

Serverless: Deploying function: auth...
Serverless: Packaging function: auth...
Serverless: Uploading function: auth (90.02 MB)...

  Serverless Error ---------------------------------------

     Request must be smaller than 69905067 bytes for the
     UpdateFunctionCode operation

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues

  Your Environment Information -----------------------------
     OS:                 win32
     Node Version:       4.3.1
     Serverless Version: 1.6.1

If it turns out that the problem is on Serverless' side, we should create an issue there.

I analyzed the issue and found the root cause (also copied in the references serverless issue):

The webpack plugin is invoked on the 'before:deploy:createDeploymentArtifacts' and 'after:deploy:createDeploymentArtifacts' hooks, which are not exposed by the AWS function deploy core plugin (there only 'deploy:function:packageFunction' is available). That's why the webpack packing is not invoked at all in this case.

The correct solution would be to hook 'before:deploy:function:packageFunction' and package the requested function chunk.

I guess the difficulty here is determining which webpack entry points map to which services in the serverless config.

Hooking into the correct events is a lot easier.

Any more progress on #110 ?

Did not have time to investigate the problem with my PR further. Currently I am implementing parts of the new package/deploy mechanism in Serverless and try to keep it compatible with the existing plugins.
Nevertheless there will be big improvements in Serverless' lifecycle model that should make it a lot easier to support hooking multiple commands with one hook.
I will try to fix and test this during the lifecycle development.

Appreciate the update!

Shifted to 2.1.0 as there are still discussions on how to improve the implementation provided in #130 .

PR #130 is merged.

Hi,

I'm running webpack 2.7.0 and serverless 1.19.0 and the problem still persist.
Adding

package:
  individually: true

Gives me the following error when deploying:

path.js:7
    throw new TypeError('Path must be a string. Received ' + inspect(path));
    ^

Is anything that I'm missing or wrongly configuring?

@nicolasdonoso Which serverless-webpack plugin version did you use? The support for package individually is currently implemented and available in the v3.0.0-individual-packaging branch which will be integrated into the upcoming v3 version.
serverless-webpack v2.x.x does not yet support it.

Can you give that branch a try and check if it solves the problem for you?

@HyperBrain thanks for the response, I added the branch that you are telling me and deployed the hole project and I get the following error:


  Cannot set property 'package' of undefined

  Stack Trace --------------------------------------------

This happens when adding:

      individually: true

After that I tried to deploy a single function and it states "Serverless: Bundling with Webpack..." what wasn't happening on previous versions, but after that I get the following error:


  ENOENT: no such file or directory, open '.../<project-name>/.webpack/.serverless/<function-name>.zip'

  Stack Trace --------------------------------------------

@nicolasdonoso Thanks for testing 👍 . Can you check that you have

package:
  individually: true

at the top-level of your serverless.yml? And verify that the handler definitions in the functions point to the correct relative paths in case you have your handler files sitting somewhere within your project.

Additionally it would be great to see your webpack.conf.js to check if the configuration there is correct. There's now the possibility to enable automatic entry/handler resolution in the webpack config. I'm quite sure it's only some configuration issue.

@HyperBrain Yes I have that on top-level of my serverless.yml. The handler definitions are pointing correctly and its generating the .webpack folder with all the functions inside as individual folders. Now its logging me the following error:


  Cannot set property 'package' of undefined

My webpack.config.js is the following:


module.exports = {
  //entry: "./functions/*.js",
  entry: fn_register,//_.assign(fn_register, slsw.lib.entries),
  target: 'node',
  module: {
    loaders: [{
      test: /\.js$/,
      loaders: ['babel-loader'],
      include: __dirname,
      exclude: /node_modules/,
    },
    {
      test: /aws-sdk/,
      loaders: ['transform-loader?aws-sdk/dist-tools/transform']
    },
    {
      test: /\.json$/,
      loaders: ['json-loader']
    }]
  },
  output: {
    libraryTarget: 'commonjs',
    path: path.join(__dirname, './.webpack'),
    filename: '[name].js'
  }
};```

** fn_register is an object thats mapping all the entry names and paths of my functions.

Can you try to use entry: slsw.lib.entries to test if the manual override causes the problem?
Additionally you can let the error create a callstack by setting SLS_DEBUG=* in your environment.
Then it is better to check.

We just tried what you told us, and it works. But we are getting this response from our function once its deployed:
Bad handler ./functions/model/job_request/get_details.handler

Can you open/extract the zip file the deployment created in .serverless for your function and check what's exactly in there?
Also check in your serverless.yml that the handler definition of your function is this:

function:
  handler: functions/model/job_request/get_details.handler

I double checked our serverless.yml and the definition was affecting the deployment.
I was using ./functions....
After removing the "./" it worked.
Thanks for the help!

😃 You're welcome

The whole project deploys correctly, but when deploying individual functions I'm getting the following error:

Serverless: Bundling with Webpack...
Time: 6122ms
                                     Asset     Size  Chunks                    Chunk Names
functions/model/job_request/get_details.js  3.84 MB       0  [emitted]  [big]  functions/model/job_request/get_details
Serverless: Packaging function: job-request-get_details...

  Error --------------------------------------------------

  ENOENT: no such file or directory, open '<project-serverless>/.webpack/.serverless/job-request-get_details.zip'```

Thanks for the info. I think you just found a small bug of the single function deploy together with the individual packaging.
Could you create an issue "V3: Deploying a single function with individual packaging does not work"
I will take care of it and fix it soon.

Ok, just created a new issue #181