question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Lambda layer is being applied before code updates.

See original GitHub issue

The Lambda layer is being applied before code changes when updating. Then the max size limit of the lambda is reached when deploying. This is either an CDK specific issue or AWS Cloud Formation, I could not find any evidence of this on the internet and consider it to be a fringe case.

Reproduction Steps

I have a deployed lambda function that is 230MB. Then after making changes to the lambda function it is reduced to ~50MB. A lambda layer is applied to the this function ~130MB. The combined size of the lambda + layer is then ~180MB which is less than the 250MB limit. When I try to deploy this I get the following cloudformation error:

...
 20/101 | 1:27:01 PM | UPDATE_FAILED        | AWS::Lambda::Function                | <LambdaFunctionName> (XXX) Function code combined with layers exceeds the maximum allowed size of 262144000 bytes. The actual size is 361955628 bytes. (Service: AWSLambdaInternal; Status Code: 400; Error Code: InvalidParameterValueException; Request ID: XXX)
...

Which looks like the Layer is applied before the code update (as the new code + layer is less than 250MB), and then fails the size constraint. The actual size it reports is the old code + layer: 230MB + 130MB = 360MB which lead me to this fringe case conclusion.

It deploys when you completely destroy the stack and then use the layer + new code. Which is the same as destroying the lambda function or manually updating the lambda with the new code first and then running the update using cloud formation/CDK.

Environment

  • CLI Version : 1.26.0
  • Framework Version: 1.32.0
  • Node.js Version: v10.16.3
  • OS : Windows & Linux
  • Language (Version): TypeScript

This is 🐛 Bug Report

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:5
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
jsheldon-qcicommented, Sep 8, 2022

We are also still experiencing this issue, and it’s causing quite a bit of pain with our deployments.

2reactions
lukeknxtcommented, Sep 12, 2021

Just confirming that I’m still experiencing this issue in 2021. Thought I was going slightly crazy until I found this.

In my experience, I had a few lambda functions that were each very fat, each having a copy of some large shared libraries. Naturally I wanted to refactor to extract the shared libraries into a layer, however after doing so, I ran into this problem where even though my functions were now tiny and the layer was fat, my cdk deploy would tell me that:

Function code combined with layers exceeds the maximum allowed size of 262144000 bytes. The actual size is 296335820 bytes.

Even though what I was seeing in the build was more like:

❯ du -sh asset.*
4.0K	asset.39c7c0b56d2b94f5320257b13eb8c25532e20918e7f37483d070959f752b3886
4.0K	asset.81c2c95c803b458187259bf4081da3e1fc7cb08551d22f75a12349273555fa49
 93M	asset.ab3b51a3705756fa3e9283340417420048ab6b4d06677dd05c319aa6d1567e95

And this was my whole deployment, so I couldn’t understand how I was breaching the 250 MB limit.

To resolve it, I had to cdk destroy and cdk deploy again which is disappointing.

Steps to reproduce from my experience are therefore something like:

  1. Produce a fat lambda function with a bunch of large libraries (almost breaching the limit)
  2. cdk deploy
  3. Move large libraries out into a layer (almost breaching the limit)
  4. Verify that combined unzipped size does not exceed the limit
  5. cdk deploy
Read more comments on GitHub >

github_iconTop Results From Across the Web

Using layers with your Lambda function - AWS Documentation
A Lambda layer is a .zip file archive that can contain additional code or other content. A layer can contain libraries, a custom...
Read more >
AWS Lambda Layers: Introduction | Knowledge Base - Dashbird
Every time the update-function-configuration option is used with the --layers argument, Lambda will replace the entire list of current layers with the new...
Read more >
AWS Lambda Use Cases: When to use Lambda layers - Lumigo
By using something like the serverless-layers plugin you can bundle all of your dependencies as a Lambda layer and automatically update the ...
Read more >
terraform-aws-modules/lambda/aws
Create, update, and publish AWS Lambda Function and Lambda Layer - see ... If you want to manage function code and infrastructure resources ......
Read more >
Working With The Lambda Layer in Keras | Paperspace Blog
That being said, you might want to perform an operation over the data that is not applied in any of the existing layers,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found