# Is it expected behaviour for Serverless to publish the entire project to each Lambda function it creates?

**URL:** <https://forum.serverless.com/t/is-it-expected-behaviour-for-serverless-to-publish-the-entire-project-to-each-lambda-function-it-creates/13441>\
**Category:** Serverless Framework\
**Tags:** aws, lambda\
**Created:** [December 20, 2020, 7:54pm UTC](https://forum.serverless.com/t/is-it-expected-behaviour-for-serverless-to-publish-the-entire-project-to-each-lambda-function-it-creates/13441 "2020-12-20T19:54:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![asker](https://avatars.discourse-cdn.com/v4/letter/a/f0a364/32.png) [@asker](https://forum.serverless.com/u/asker)\
**Post date:** [December 20, 2020, 7:54pm UTC](https://forum.serverless.com/t/is-it-expected-behaviour-for-serverless-to-publish-the-entire-project-to-each-lambda-function-it-creates/13441/1 "2020-12-20T19:54:19Z")

</div>

My serverless project has the following structure:

```auto
src/
    handlers/
        handler.js
        otherhandler.js
    lib/
        get-something.js
serverless.yml
package.json

```

Any one of my handlers may look like this:

```auto
const getSomething = require("../lib/get-something");

module.exports.getSomething = async () => {
    return getSomething();
};

```

I do this because I dislike having all my code in one big Lambda function.

Whenever I deploy, each Lambda function that is created contains the _entire_ project. The entire `node_modules` and `src` folder is published along with an auto-generated file called `s_getSomething.js`.

Is this the intended behavior? I assume that anything other than this would webpack-like functionality of detecting dependencies, tree-shaking and so on.

---

<div class="post-metadata">

**Author:** ![armenard](https://avatars.discourse-cdn.com/v4/letter/a/edb3f5/32.png) [@armenard](https://forum.serverless.com/u/armenard)\
**Post date:** [December 23, 2020, 1:35pm UTC](https://forum.serverless.com/t/is-it-expected-behaviour-for-serverless-to-publish-the-entire-project-to-each-lambda-function-it-creates/13441/2 "2020-12-23T13:35:48Z")

</div>

Serverless can use webpack for you – put exclude/include in the serverless yaml file to specify what things to keep when packaged and what to drop. Put the general rules at the top of the serverless.yaml under package, and then override them later in individual functions using package again – my serverless.yaml looks like this:

package:  
exclude:  
- package.json  
- serverless.yml  
- README.md  
- .gitignore  
- .vs/\*\*  
- release\_notes/\*\*  
- src/\*\*  
- resources/\*\*  
- node\_modules/\*\*

functions:  
MyFunction:  
package:  
- /src/lambda/MyFunction.js  
- /libs/requiredLibrary/requiredFile.js
