Hello folks! Been real deep in AWS as I learn more about the services and today's tip comes straight from the AWS team that I have been working with! If you don't want to read the rest, here's the quick TL;DR:
There's a known issue (as of 01/01/2023 is when we started dealing with it) with AWS Lambdas where even if the size is over the limit, sometimes it can still be deployed to your environments. The best way to ensure you never experience any issues is to be sure that you are under the size limit:
250 MB for uncompressed data (including layers)1
50 MB for compressed data (including layers)
Now here's an overview of some notes and tips that I learned from my investigation! First off, it doesn't matter if this is done via CloudFormation, CodePipeline or any of their services, it all eventually has to go through Lambdas and that is when you will hit your size issue. The error message will appear as something like so:
Code uncompressed size is greater than max allowed size of 272629760. (Service: Lambda, Status Code: 400, Request ID: 99a3c30a-b444-4558-ba5f-13ce38922f5b)" (RequestToken: dc727a33-6f29-e240-1452-97c228fe2ad0, HandlerErrorCode: InvalidRequest)
The error message is pretty solid in that it immediately tells you that your code is larger than what they allow. However, welcome to the first obstacle that I encountered - depending on the OS and even how you unzip (GUI vs terminal), there's a slight size difference. Going with the terminal will show you the smallest size (command for that is du -h
which stands for disk usage) while the GUI can be larger. The difference is negligible but something to note if you are wondering why there is a size difference.
Now comes to the biggest revelation (besides the known issue) that helped me solve my issue: AWS Lambda runtime environments have their own aws-sdk
so you do not need to include that in your packages. Let me repeat that: You do not need to include aws-sdk
in your packages.
For us, that immediately removed 80 MB and helped us well be under the limit. And then it took another couple weeks continuously talking to AWS support to determine that it is a known issue why even though we were over the size limit, we were still able to deploy sometimes.
1https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html
Top comments (0)