---
title: "Discussion on \"How we reduced our NodeJs app size on AWS Lambda by over 80% 😮\" | Hashnode"
description: "Discussion on \"How we reduced our NodeJs app size on AWS Lambda by over 80% 😮\". Tips on how to reduce your node app size and the benefits"
url: "https://hashnode.com/posts/how-we-reduced-our-nodejs-app-size-on-aws-lambda/613724b7ef28811d8bed6944"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [How we reduced our NodeJs app size on AWS Lambda by over 80% 😮](https://log.victoranuebunwa.com/how-we-reduced-our-nodejs-app-size-on-aws-lambda?utm_source=hashnode&utm_medium=feed)

Tips on how to reduce your node app size and the benefits

Sep 7, 2021 · 5 min read · log.victoranuebunwa.com  
Updated May 21, 2025  
Read the article

## Written by

[Victor Anuebunwa](https://hashnode.com/@AVONnadozie)

@AVONnadozie

  
[View profile](https://hashnode.com/@AVONnadozie)

## Responses 2

Markdown supported · ⌘↵ to post

[dauda cindy](https://hashnode.com/@Kelechikay)

[Sep 8, 2021](https://hashnode.com/posts/how-we-reduced-our-nodejs-app-size-on-aws-lambda/613724b7ef28811d8bed6944/comment/6138e2307abd7c45f70f4c80)

Great !!! 👍👍👍

[Pavel Denisjuk](https://hashnode.com/@pavel910)

[Sep 8, 2021](https://hashnode.com/posts/how-we-reduced-our-nodejs-app-size-on-aws-lambda/613724b7ef28811d8bed6944/comment/613899988b7ef170483a0f0f)

Other things to consider, which work great for us at Webiny, are:

1) Use webpack to bundle your handlers. With this you only get production dependencies that you _actually use in code_ without even thinking about it, + everything gets minified, which greatly reduces the handler size. This also provides the benefit of using tools to analyze your webpack bundle to identify large dependencies and potentially get rid of them.

With webpack it's easy to exclude any module (like `aws-sdk`) from the bundle, using the `externals` parameter. This brings us to the next point:

2) Extract dependencies you share in multiple handlers into [Lambda Layers](https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html). Layers can contain both 3rd party npm modules as well as your own project level packages. Once the layer is attached to your Lambda, you import those dependencies as any other node module.

If you use this approach, you don't need to worry about accidentally leaving `aws-sdk` in the production dependencies, because webpack will exclude it anyway. And you can also exclude all the dependencies that will be provided by the Lambda Layers.

[Matej](https://hashnode.com/@konradmatej)

[Sep 8, 2021](https://hashnode.com/posts/how-we-reduced-our-nodejs-app-size-on-aws-lambda/613724b7ef28811d8bed6944/comment/6138962d83248670799c0e7a)

Wow, I had no idea that `aws-sdk` is so huge! I'll definitely keep that one in my mind next time I'm working with it!

Really helpful! 🙌

[Aditya Mitra](https://hashnode.com/@aditya-mitra)

[Sep 8, 2021](https://hashnode.com/posts/how-we-reduced-our-nodejs-app-size-on-aws-lambda/613724b7ef28811d8bed6944/comment/61384b198b7ef170483a0483)

I use serverless functions a lot and the tips you provided in this article are really helpful!

Some of the tips will be really helpful in other serverless platforms which have a strict runtime of 1s.

Just because to avoid installing unnecessary packages I prefer writing my own functions whenever possible.

[Aditya Mitra](https://hashnode.com/@aditya-mitra)

[Sep 8, 2021](https://hashnode.com/posts/how-we-reduced-our-nodejs-app-size-on-aws-lambda/613724b7ef28811d8bed6944/comment/61384b198b7ef170483a0483#reply-61384c8a83248670799c0430)

Another thing that I wanted to share:

The `npm install --production` if there is no build required. For example, if the project uses typescript, it would be added as a dev dependency and needs to be installed for the build.

For that reason, I do `npm ci` first for build and then do `npm prune --production` for checking if the application can boostrap.
