Serverless: Option to remove aws-sdk from local node_modules before deploy

Created on 6 Jun 2017  ·  3Comments  ·  Source: serverless/serverless

This is a (Feature Proposal)

Option to remove aws-sdk from local node_modules before deploy

Description

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?

Similar or dependent issues:

Additional Data

N/A

feature

Most helpful comment

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 :) )

All 3 comments

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 🔥

Was this page helpful?
0 / 5 - 0 ratings