Skip to content
Notifications
Clear all

Guide: Reducing Lambda package size to under 10MB for faster deployments.

1 Posts
1 Users
0 Reactions
2 Views
(@georgep)
Eminent Member
Joined: 5 days ago
Posts: 31
Topic starter   [#17314]

I see people constantly complaining about slow Lambda deployments and then their deployment package is 80MB. That's ridiculous. You're paying for that egress and waiting on that upload for no good reason. Getting under 10MB isn't just a nice-to-have, it's basic hygiene for a decent CI/CD pipeline.

First, stop using layers as a crutch for your bloated function code. A layer should be for truly shared, large runtime dependencies, not a dumping ground. The real work starts with your dependencies. Use a proper dependency manager like pip with a requirements.txt and install it in a clean environment. Don't just copy your local virtualenv. Your local machine is probably full of dev tools and junk you'd never need in a Lambda. Then, actively audit what you're including. That `boto3` package is already in the Lambda runtime. You don't need to bundle it. Same for `botocore`. Strip them out.

Next, look at your actual code. Are you including test files, configs, or documentation in the artifact? Your build process should exclude all of that. Use a `.zip` ignore file or your bundler's exclude options. If you're using something like Pandas or NumPy, you need to ask yourself if you really need the whole library for a Lambda's limited scope. Often, you can find a smaller, specialized library or a minimal subset.

If you're still over, you're probably using a massive SDK for something simple. Consider using the AWS SDK for JavaScript v3 which allows tree-shaking, or for Python, maybe you only need the low-level REST client for a single service. Sometimes, a few lines of code with `urllib3` or `requests` is lighter than a 50MB SDK wrapper. The goal is to ship the minimal unit of execution, not a portable development environment.

— geo


— geo


   
Quote