Serverless Framework "Request entity too large" deploy package in CI
AWS rejected the upload because it exceeds a hard size limit: a Lambda zip over the direct-upload threshold, a deployment package too large, or an inline template that is too big. Serverless surfaces "Request entity too large".
What this error means
serverless deploy fails with "RequestEntityTooLargeException" or "Request entity too large" while updating function code or creating the stack.
Error:
An error occurred: HelloLambdaFunction - Request entity too large
(Service: AWSLambda; Status Code: 413; Error Code: RequestEntityTooLargeException; ...)Common causes
The packaged function zip is too large
Bundling node_modules or large assets pushed the deployment package past the Lambda size limit for that upload path.
Unnecessary files in the package
Tests, docs, and dev dependencies were packaged, inflating the zip well beyond what the function needs.
How to fix it
Shrink the package
- Exclude dev files and unused modules with package patterns.
- Package each function individually so they stay small.
- Move heavy shared code into a Lambda layer.
package:
individually: true
patterns:
- '!**/*.test.js'
- '!node_modules/.cache/**'Bundle and tree-shake the code
Use a bundler plugin to ship only the code the function imports.
npm install --save-dev serverless-esbuildHow to prevent it
- Exclude tests and dev dependencies from the package.
- Use
package.individuallyfor multi-function services. - Bundle with esbuild/webpack to cut package size.