我从AWS代码构建中上传我的lambda函数源。我的Python脚本使用NLTK,因此需要大量数据。我的.zip包太大了,出现了一个RequestEntityTooLargeException。我想知道如何增加通过UpdateFunctionCode命令发送的部署包的大小。
我使用AWS CodeBuild将源代码从GitHub存储库转换为AWS Lambda。下面是关联的buildspec文件:
version: 0.2
phases:
install:
commands:
- echo "install step"
- apt-get update
- apt-get install zip -y
- apt-get install python3-pip -y
- pip install --upgrade pip
- pip install --upgrade awscli
# Define directories
- export HOME_DIR=`pwd`
- export NLTK_DATA=$HOME_DIR/nltk_data
pre_build:
commands:
- echo "pre_build step"
- cd $HOME_DIR
- virtualenv venv
- . venv/bin/activate
# Install modules
- pip install -U requests
# NLTK download
- pip install -U nltk
- python -m nltk.downloader -d $NLTK_DATA wordnet stopwords punkt
- pip freeze > requirements.txt
build:
commands:
- echo 'build step'
- cd $HOME_DIR
- mv $VIRTUAL_ENV/lib/python3.6/site-packages/* .
- sudo zip -r9 algo.zip .
- aws s3 cp --recursive --acl public-read ./ s3://hilightalgo/
- aws lambda update-function-code --function-name arn:aws:lambda:eu-west-3:671560023774:function:LaunchHilight --zip-file fileb://algo.zip
- aws lambda update-function-configuration --function-name arn:aws:lambda:eu-west-3:671560023774:function:LaunchHilight --environment 'Variables={NLTK_DATA=/var/task/nltk_data}'
post_build:
commands:
- echo "post_build step"启动管道时,我有RequestEntityTooLargeException,因为我的.zip包中有太多的数据。请参阅下面的构建日志:
[Container] 2019/02/11 10:48:35 Running command aws lambda update-function-code --function-name arn:aws:lambda:eu-west-3:671560023774:function:LaunchHilight --zip-file fileb://algo.zip
An error occurred (RequestEntityTooLargeException) when calling the UpdateFunctionCode operation: Request must be smaller than 69905067 bytes for the UpdateFunctionCode operation
[Container] 2019/02/11 10:48:37 Command did not exit successfully aws lambda update-function-code --function-name arn:aws:lambda:eu-west-3:671560023774:function:LaunchHilight --zip-file fileb://algo.zip exit status 255
[Container] 2019/02/11 10:48:37 Phase complete: BUILD Success: false
[Container] 2019/02/11 10:48:37 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: aws lambda update-function-code --function-name arn:aws:lambda:eu-west-3:671560023774:function:LaunchHilight --zip-file fileb://algo.zip. Reason: exit status 255当我减少要下载的NLTK数据时,一切都正常工作(我只尝试使用包stopwords和wordnet )。
有人有办法解决这个“尺寸限制问题”吗?
发布于 2019-02-11 14:44:39
不能增加Lambda的部署包大小。AWS限制在AWS Lambda开发人员指南中描述。有关这些限制是如何工作的更多信息,请参见这里。实际上,解压缩包的大小必须小于250 In (262144000字节)。
PS:使用图层并不能解决尺寸大小的问题,尽管这有助于管理&也许更快的冷启动。包大小包括图层- Lambda层。
一个函数一次最多可以使用5层。函数和所有层的总解压缩大小不能超过解压缩部署包大小限制250 MB。
更新2020年12月:根据AWS博客,正如用户jonnocraig 在这个答案中所指出的,如果您为应用程序构建了一个容器并在Lambda上运行它,您可以克服这些限制。
发布于 2021-02-17 13:59:19
如果有人在2020年12月后偶然发现这个问题,那么AWS已经进行了一次重大的更新,以支持Lambda函数作为容器映像(最高可达10 up!!)。更多信息这里
发布于 2020-07-07 14:41:10
AWS Lambda函数可以挂载EFS。可以使用EFS加载大于AWS Lambda的250 MB包部署大小限制的库或包。
关于如何设置它的详细步骤如下:https://aws.amazon.com/blogs/aws/new-a-shared-file-system-for-your-lambda-functions/
在高层次上,这些变化包括:
https://stackoverflow.com/questions/54632009
复制相似问题