question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Instructions on getting warmup to work with serverless-webpack

See original GitHub issue

I preface this with the fact that I’m a webpack newbie so this may be suboptimal.

If using the serverless-webpack plugin then you need to make some changes to webpack.config.js to get serverless-plugin-warmup to work.

  1. Add a new chunk for warmup with the specific path that the warmup plugin uses.
  2. Add an output section as per above. This ensures that the warmup handler is appears in the bundle at the same path as it would have originally.

For example:

  entry: {
    handler: [/* possibly other entry points like babel-polyfill, ... */ './handler.js'],
    '_warmup/index': './_warmup/index.js',
  },
  output: {
    libraryTarget: 'commonjs',  // <- as per serverless-webpack README
    path: '.webpack',
    filename: '[name].js',
  },

An issue with this setup is that serverless webpack invoke no longer works because _warmup does not exist then.

Another potential issue is the reliance on the _warmup/index.js path not changing.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
mikestaubcommented, May 11, 2017

@damonmaria I simply copy the whole _warmup dir with copy-webpack-plugin like so:

plugins: [new CopyWebpackPlugin({ from: '_warmup', to: '_warmup' })],

1reaction
lucasklaassencommented, Nov 25, 2017

For anyone else that finds this thread, the following webpack.config.js works for me now:

const nodeExternals = require('webpack-node-externals');
const path = require('path');
const slsw = require('serverless-webpack');

module.exports = {
  entry: slsw.lib.entries,
  target: 'node',
  externals: [nodeExternals()],
  output: {
    libraryTarget: 'commonjs',
    path: path.resolve(__dirname, '.webpack'),
    filename: '[name].js' // this should match the first part of function handler in serverless.yml
  },
  module: {
    loaders: [
      {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        loaders: ["babel-loader"]
      },
      {
        test: /\.json$/,
        loader: 'json-loader'
      }
    ]
  }
};

serverless: 1.24.1 serverless-plugin-warmup: 3.3.0-rc.1 serverless-webpack: 4.0.0 webpack: 4.0.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Instructions on getting warmup to work with serverless-webpack
Add a new chunk for warmup with the specific path that the warmup plugin uses. Add an output section as per above. This...
Read more >
Serverless Plugin Warmup
WarmUp solves cold starts by creating a scheduled lambda (the warmer) that invokes all the selected service's lambdas in a configured time interval...
Read more >
Optimizing your Lambda cold starts with serverless-webpack
A comprehensive guide to using the serverless-webpack plugin for optimizing your Lambda cold start times, with common gotchas and ...
Read more >
Resolving Serverless Webpack Issues | by Dustin Goodman
A story about how I debugged an issue with our webpack bundles on a serverless infrastructure and the key takeaways about developing ...
Read more >
Serverless Webpack in Lambda Simplified 101 - Learn | Hevo
This blog explains the different aspects of Serverless Webpack in Lambda. In addition to that, it describes AWS Lambda as well.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found