Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single function deploy does not invoke the plugin #107

Closed
HyperBrain opened this issue Feb 24, 2017 · 20 comments
Closed

Single function deploy does not invoke the plugin #107

HyperBrain opened this issue Feb 24, 2017 · 20 comments
Labels
Milestone

Comments

@HyperBrain
Copy link
Member

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.

@HyperBrain
Copy link
Member Author

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.

@jdbevan
Copy link
Contributor

jdbevan commented Mar 3, 2017

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.

@jtrein
Copy link

jtrein commented Mar 23, 2017

Any more progress on #110 ?

@HyperBrain
Copy link
Member Author

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.

@jtrein
Copy link

jtrein commented Mar 23, 2017

Appreciate the update!

@HyperBrain
Copy link
Member Author

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

@HyperBrain
Copy link
Member Author

PR #130 is merged.

@nicolasdonoso
Copy link

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?

@HyperBrain
Copy link
Member Author

@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?

@nicolasdonoso
Copy link

nicolasdonoso commented Aug 4, 2017

@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 --------------------------------------------

@HyperBrain
Copy link
Member Author

@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.

@nicolasdonoso
Copy link

@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.

@HyperBrain
Copy link
Member Author

HyperBrain commented Aug 4, 2017

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.

@nicolasdonoso
Copy link

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

@HyperBrain
Copy link
Member Author

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

@nicolasdonoso
Copy link

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!

@HyperBrain
Copy link
Member Author

😃 You're welcome

@nicolasdonoso
Copy link

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'```

@HyperBrain
Copy link
Member Author

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.

@nicolasdonoso
Copy link

nicolasdonoso commented Aug 4, 2017

Ok, just created a new issue #181

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants