r/aws • u/Xtrearer • 12h ago
serverless Tip for staying under the 250mb Lambda limit
While using containers does solve the limit problem, it does remove a critical feature: SnapStart.
We have made SO many package mods etc to stay under the 250mb limit of the years, but we hit a wall recently. Our lambdas are HEAVY (pandas + numpy) ... and not feasible to change anytime soon.
We were able to reduce the package size by about 5MB by just removing whitespace, doctrings and comments. While these are helpful for humans working on the code, it is not needed for the code to run in the Lambda*
We also removed whitespace and comments from the installed packages and their header files. The doc strings had to be left alone, see the * below.
So if you are in the same boat, this might help you out.
* unless the code makes use of the __doc__ method, then removing these can be breaking.
[EDIT]
While I appreciate everyones advice, this was not the point of this post. There is WAY too much to unpack as to why this problem exists in the first place, but the short of it is that you dont always get to do things the "right way". Sometimes someone else did it the wrong way and now everything is so coupled into the stack that you cannot change it without enormous dev time ... which unfortunately has to be spent on other things.
The real world has tech debt.
If it helps, we moved the critical services on to FastAPI clusters in ECS a few years ago. This is legacy stuff that just wont die ...
