package: individually: true generates huge files when using the same handler file for multiple functions
See original GitHub issueThis is a Bug Report
Description
For bug reports:
- What went wrong?
I ran
serverless deploy -s test
and checked the code size of the functions in the lambda console. The size had gone up from 326.9 kB to 36.4MB. - What did you expect should have happened? The size to go down, and differ between the packages
- What was the config you used?
serverless.yml
package:
individually: true
custom:
webpackIncludeModules: true
webpack.config.js
const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
const slsw = require('serverless-webpack')
const Visualizer = require('webpack-visualizer-plugin')
module.exports = {
entry: slsw.lib.entries,
target: 'node',
externals: ['aws-sdk'],
plugins: [
new UglifyJSPlugin(),
new Visualizer({filename: '../webpack-stats.html'}),
]
}
- What stacktrace or error message from your provider did you see?
Additional Data
- Serverless-Webpack Version you’re using: github master (git://github.com/elastic-coders/serverless-webpack.git#85560afce2c60cdf6c4ba54392e45e991e0cc595)
- Webpack version you’re using: 3.5.5
- Serverless Framework Version you’re using: 1.20.2
- Operating System: Debian Stretch
- Stack Trace (if available):
My serverless.yml
has 3 functions, all in the same file, handler.js
.
Issue Analytics
- State:
- Created 6 years ago
- Comments:16 (6 by maintainers)
Top Results From Across the Web
Packaging - Serverless Framework
To enable individual packaging set individually to true in the service or function wide packaging settings. Then for every function you can use...
Read more >Deploy multiple functions using serverless creating each ...
Hi, What I am suggesting is separate lambda functions/entry points only. Each lambda function is is separate .java file. In my case, I...
Read more >Breaking a large serverless.yml into manageable chunks
Breaking the file. Start by creating 2 new serverless.yml files in the function sub folders randomGenerator and uuidGenerator. And copy the ...
Read more >Azure Functions best practices | Microsoft Learn
To reduce latency, create the storage account in the same region as the function app. To improve performance in production, use a separate ......
Read more >Best practices for organizing larger serverless applications
Many serverless applications begin as monolithic applications. ... Using these packages in Lambda functions results in architectures like ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It is fixed in the attached PR, but consider changing the project layout as mentioned above 😉
@msl-kabo I will fix the wrong packaging issue, but I see a general flaw in the layout of the project. Webpack can only set whole files as entries (see here). So, if all of your handlers are exports of the same file, this file will be optimized (with all exports that it has in it). This is not optimizable on a function level though.
The benefit from Webpacks optimization is only usable, if you separate the handler layer from the business logic, i.e. you should create 3 handlers for the functions that call the specific export from the lib files. Then Webpack will analyze each handler separately and only use the code used by each specific handler that is accessed from the handlers.
Sample:
File system:
The handlers now export a handler function and each handler calls into lib/handler.functionX. Now Webpack can optimize the whole code correctly.