InvalidParameterValueException aws resource_error ai_generated true

An error occurred (InvalidParameterValueException) when calling the CreateFunction operation: Unzipped size must be smaller than 262144000 bytes

ID: aws/lambda-s3-zip-extract-failed

Also available as: JSON · Markdown · 中文
82%Fix Rate
88%Confidence
1Evidence
2023-08-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
AWS Lambda API 2015-03-31 active — — —
AWS SDK for Python 1.27.0 active — — —
SAM CLI 1.80.0 active — — —

Root Cause

The Lambda deployment package's unzipped size exceeds the 250 MB unzipped limit, including layers and code.

generic

中文

Lambda 部署包的解压后大小(包括层和代码)超过了 250 MB 的限制。

Official Documentation

https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html

Workarounds

  1. 75% success Reduce deployment package size by removing unused dependencies. For Python, use a virtual environment and prune with 'pip install --no-deps' for only required packages. Then rebuild and redeploy.
    Reduce deployment package size by removing unused dependencies. For Python, use a virtual environment and prune with 'pip install --no-deps' for only required packages. Then rebuild and redeploy.
  2. 85% success Use AWS Lambda layers to offload large libraries (e.g., numpy, pandas) from the deployment package. Create a layer with the library, and reference it in the function configuration.
    Use AWS Lambda layers to offload large libraries (e.g., numpy, pandas) from the deployment package. Create a layer with the library, and reference it in the function configuration.
  3. 90% success Use container image support for Lambda: package your function as a Docker image (up to 10 GB) instead of a .zip file. Example: 'docker build -t myfunction . && aws ecr create-repository --repository-name myfunction && docker push ...'.
    Use container image support for Lambda: package your function as a Docker image (up to 10 GB) instead of a .zip file. Example: 'docker build -t myfunction . && aws ecr create-repository --repository-name myfunction && docker push ...'.

中文步骤

  1. 通过删除未使用的依赖来减少部署包大小。对于 Python,使用虚拟环境,并仅用 'pip install --no-deps' 安装必要的包。然后重新构建并部署。
  2. 使用 AWS Lambda 层将大型库(例如 numpy、pandas)从部署包中分离。创建一个包含该库的层,然后在函数配置中引用它。
  3. 使用 Lambda 容器镜像支持:将函数打包为 Docker 镜像(最大 10 GB),而不是 .zip 文件。示例:'docker build -t myfunction . && aws ecr create-repository --repository-name myfunction && docker push ...'。

Dead Ends

Common approaches that don't work:

  1. 90% fail

    Compressing the deployment package more aggressively (e.g., using maximum compression) doesn't reduce the unzipped size, which is what matters for the limit.

  2. 70% fail

    Deleting unnecessary files from the package but still including large libraries (e.g., full Python packages) often fails because the unzipped size remains above 250 MB.