(lambda): Get Function code + layer exceeds maximum size error when it does not
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
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 | (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: Bug Report
Contributor guide
Research direction
Start by reproducing the reported update sequence for an AWS Lambda function whose code shrinks from about 230 MB while a 130 MB layer remains attached, using CDK and CloudFormation. Compare the deployment behavior with updating the code before applying the layer. Done means an in-place update succeeds when the final combined size is below 262144000 bytes, or the issue is clearly identified as an AWS CloudFormation limitation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100