This article is part of a series on sls-mentor, an open-source, highly configurable, automated best-practice audit tool for AWS serverless architectures.
The lighter, the better
A light bundle will positively impact your Serverless architecture for at least two reasons.
1. A light deployment package reduces the cold start of your Lambda function
Reducing the size of the bundle will reduce the time it takes to upload the bundle, and also significantly reduce the lambda's cold start.
You should use appropriate tools to bundle your Lambda functions with a minimal size. For example, the Serverless Framework, with the serverless-esbuild plugin, automatically bundles your code and uploads it to AWS.
2. AWS enforces quotas on deployment resources
Smaller bundles will help you respect AWS quotas, allowing more functions in your AWS account!
Resource | Quota |
---|---|
Lambda function deployment package (zipped) | 50 MB |
Lambda function deployment package (uncompressed) | 250 MB |
Total deployment packages | 75 GB |
sls-mentor is your solution to easily check the size of your bundles
sls-mentor now offers a new rule to warn you when uploading bundles over 5 MB.
sls-mentor comes with many rules to help you make the best decisions for your Serverless project. It will help you identify where your code can be optimized to achieve better performance at a lower cost.
sls-mentor how-to
npm install @sls-mentor/sls-mentor
npx sls-mentor -p <your_aws_profile> -c <your_stack_name>
sls-mentor is available on NPM. You will find instructions to use sls-mentor in your CI.
See also
There are plenty of tools out there to optimize the size of your bundles. For instance the Serverless Analyze Bundle Plugin integrates with the Serverless Framework and helps you diagnose which of your NodeJS dependency is not properly tree-shaked.
For more details on bundle size impact, take a look at Mikhail Shilkov's blog.
Top comments (0)