Reputation: 44376
Although my app is fairly simple, it was deploying at 107Mb gzipped, and then I made some change that made it so large it wouldn’t deploy at all. What do I do?
Upvotes: 1
Views: 2336
Reputation: 44376
Anything you don’t need — goes. Delete your node_modules/
directory and reinstall it to be sure it’s clean.
Anything you don’t need a run-time, mark as a dev-dependency, and put
package:
excludeDevDependencies: true
in your serverless.yml
. Things you don’t need a run-time include compilers, type-libraries, and... Node.
Yeah, if you are like me, and prefer to develop in Node/Express and then deploy to Serverless, remember that Lambda runs its own version on Node, so your Node is a dev-dependency. Ditto for things that only Node uses, like ts-node
and body-parser
.
The serverless.yml
should include the stuff you need, not exclude the stuff you don’t. I write in Typescript (and you should too) and set my tsconfig.json
to write everything to build/
, so my entire package statement in serverless.yml
is
package:
excludeDevDependencies: true
include:
- build/**
Don’t add node_modules/**
— the deployment process does that automatically and if you include it explicitly, you will defeat the excludeDevDependencies
setting.
You can practice by doing the following:
sls package
du -m -d 1 .serverless
The first statement quickly makes up the package, and then stops; the second lists the megabytes used by each artifact. If there is a .zip file that looks too big, unzip it and then use du
more to investigate what is taking up all the room.
By using these techniques, I got the 107Mb package down to 10Mb.
Upvotes: 3