Option to remove aws-sdk from local node_modules before deploy
aws-sdk alone is a huge node module (over 20mb unzipped) and along with all its dependencies it weighs in sufficiently to prevent in-browser code edits on the lambda platform.
A user may want to use something which depends on aws-sdk (e.g. @awspilot/dynamodb
) - but this will run fine with lambda's native aws-sdk module.
Currently you can manually remove aws-sdk and its dependencies and thus shrink your function package.zip by, using my case as an example, a factor of 25.
Could it be an option for serverless to remove these unnecessary modules before packaging/deploying?
N/A
Hey @davepwsmith thanks for opening 👍
You can use the exclude
/ include
rules to define globs which will describe what should be excluded / included in your deployment package (see: https://serverless.com/framework/docs/providers/aws/guide/packaging#exclude--include).
We're also working on #2709 which might be related.
FWIW: _Now_ it suffices to add aws-sdk
as a devDependency
. It will then be excluded automagically and because the AWS Lambda Node.JS runtime has the aws-sdk embedded your Lambda should still work (mine did :) )
@ChristianUlbrich Thanks for sharing!
Just shaved off 9mb of package size with moving aws-sdk
to devDependency
🔥
Most helpful comment
FWIW: _Now_ it suffices to add
aws-sdk
as adevDependency
. It will then be excluded automagically and because the AWS Lambda Node.JS runtime has the aws-sdk embedded your Lambda should still work (mine did :) )