serverless-layers: AWS Error: Function code combined with layers exceeds the maximum allowed size of 262144000 bytes
Issue
Just dropping this down somewhere to note / for people with this problem. Not sure if it’s a bug or expected behaviour.
I tried to introduce serverless-layers
to my existing project and got:
An error occurred: *** - Function code combined with layers exceeds the maximum allowed size of 262144000 bytes
The zip of the code was now only 40kb and the layer 40mb (150mb decompressed). However the previous bundle code size was pretty large and I think CloudFormation was trying to first apply the layer to the function before updating the function code which resulted in the error above.
Workaround
I deleted the stack and re-created it. An alternative (although not tested) update the code to something with no imports deploy. Once successful try and add layers to the project.
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 21
- Comments: 19 (1 by maintainers)
@ptimson I found a different workaround that might be slightly better, but still requires downtime of the service. I commented out following lines after each function:
for all of my functions. This was my one change and I deployed like this once. Once that deployed successfully I added those lines back and was able to deploy again.
It’s sad that this still appears to be the only solution. Makes creating new deployments a much more complicated ordeal now that you need to choreograph new layer uploads and function references as two distinct steps.
Same, this worked for chalice too! ❤️
Just wanted to say Thank You as this solved my problem today as well.
Thank you – this worked for me, too.
Hi @joelash, I’m got some time to investigate this issue as well, still not 100% sure yet why happening. But I reckon you guys could try using
--no-compile
to avoid generating*.pyc
files. It would reduce considerably the layer size.