Skip to content
Latchkey

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.

serverless
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

  1. Exclude dev files and unused modules with package patterns.
  2. Package each function individually so they stay small.
  3. Move heavy shared code into a Lambda layer.
serverless.yml
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.

Terminal
npm install --save-dev serverless-esbuild

How to prevent it

  • Exclude tests and dev dependencies from the package.
  • Use package.individually for multi-function services.
  • Bundle with esbuild/webpack to cut package size.

Frequently asked questions

What causes ""Request entity too large""?
Bundling node_modules or large assets pushed the deployment package past the Lambda size limit for that upload path.
How do I fix "Request entity too large"?
Shrink the package

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card