Fixing AWS Lambda 'Code uncompressed size is greater than max allowed size' during deployment

intermediateโ˜๏ธ AWS2026-05-30| AWS CLI, Serverless Framework, AWS SAM, Terraform, Node.js/Python/Java runtime

Error Message

An error occurred (InvalidParameterValueException) when calling the UpdateFunctionCode operation: Code uncompressed size is greater than 262144000 bytes
#aws-lambda#deployment#serverless

The 250MB Wall: Why Your Deployment FailedAWS Lambda has a strict hard limit for deployment packages: 50 MB for zipped uploads and 250 MB for the uncompressed content. When you try to deploy a function that exceeds this limit, the AWS API returns the following error:

An error occurred (InvalidParameterValueException) when calling the UpdateFunctionCode operation: Code uncompressed size is greater than 262144000 bytes

This usually happens when your project includes heavy dependencies (like NumPy, Pandas, or heavy Node modules), large binary files, or local documentation folders that shouldn't be in the production bundle.

Analyzing the Root CauseThe 262,144,000 bytes mentioned in the error is exactly 250 MB. AWS calculates this by summing up every file in your package after it is unzipped in the Lambda execution environment. If you use the AWS CLI or tools like Serverless Framework, the package is zipped locally, but AWS still checks the final footprint.

Common culprits include:

  • node_modules: Including devDependencies by mistake.- Python site-packages: Large data science libraries.- Temporary files: .git folders, cache files, or test data.- Binaries: Including ffmpeg or headless browsers directly in the zip.### Quick Fix: Optimize Your PackageBefore changing your architecture, try to slim down your current deployment package.

1. Prune DependenciesEnsure you are only packaging production dependencies. For Node.js, run:

npm prune --production

For Python, use a virtual environment and only install what's in requirements.txt, avoiding global system packages.

2. Use a Lambda Ignore FileIf you use the Serverless Framework or AWS SAM, use an exclude pattern in your configuration. Create or update your serverless.yml:

package:
  patterns:
    - '!node_modules/aws-sdk/**' # Already provided by Lambda runtime
    - '!.git/**'
    - '!tests/**'
    - '!docs/**'

Permanent Fix 1: Move Dependencies to Lambda LayersIf your code is small but your dependencies are large, move the libraries to a Lambda Layer. This separates your function code from the heavy lifting.

  • Create a layer containing only the node_modules or python folder.- Attach the layer to your function.- The 250MB limit still applies to the sum of the function and all layers, but layers make it easier to manage and share code.### Permanent Fix 2: Switch to Container Images (Recommended)If you cannot get your package under 250 MB (common in Machine Learning or heavy Java apps), the best solution is to package your Lambda as a Docker Container Image. Lambda container images have a much higher limit: 10 GB. Steps to migrate:
  • Create a Dockerfile using an AWS Lambda base image.- Copy your code and install dependencies inside the image.- Push the image to Amazon ECR (Elastic Container Registry).- Update your Lambda function to use the container image instead of a .zip file.Example Dockerfile for a Python function:
FROM public.ecr.aws/lambda/python:3.9

# Install dependencies
COPY requirements.txt .
RUN pip install -r requirements.txt

# Copy function code
COPY app.py .

# Set the CMD to your handler
CMD [ "app.lambda_handler" ]

Verification: How to confirm the fixAfter applying one of the fixes above, trigger a new deployment. You can verify the current size using the AWS CLI:

aws lambda get-function --function-name your-function-name --query 'Configuration.CodeSize'

If you switched to a container image, the CodeSize attribute will reflect the metadata, but you will no longer face the 250MB uncompressed limit error.

Related Error Notes