首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何增加AWS部署包(RequestEntityTooLargeException)的最大大小?

如何增加AWS部署包(RequestEntityTooLargeException)的最大大小?
EN

Stack Overflow用户
提问于 2019-02-11 13:49:01
回答 12查看 78.2K关注 0票数 34

我从AWS代码构建中上传我的lambda函数源。我的Python脚本使用NLTK,因此需要大量数据。我的.zip包太大了,出现了一个RequestEntityTooLargeException。我想知道如何增加通过UpdateFunctionCode命令发送的部署包的大小。

我使用AWS CodeBuild将源代码从GitHub存储库转换为AWS Lambda。下面是关联的buildspec文件:

代码语言:javascript
复制
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包中有太多的数据。请参阅下面的构建日志:

代码语言:javascript
复制
[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数据时,一切都正常工作(我只尝试使用包stopwordswordnet )。

有人有办法解决这个“尺寸限制问题”吗?

EN

回答 12

Stack Overflow用户

回答已采纳

发布于 2019-02-11 14:44:39

不能增加Lambda的部署包大小。AWS限制在AWS Lambda开发人员指南中描述。有关这些限制是如何工作的更多信息,请参见这里。实际上,解压缩包的大小必须小于250 In (262144000字节)。

PS:使用图层并不能解决尺寸大小的问题,尽管这有助于管理&也许更快的冷启动。包大小包括图层- Lambda层

一个函数一次最多可以使用5层。函数和所有层的总解压缩大小不能超过解压缩部署包大小限制250 MB。

更新2020年12月:根据AWS博客,正如用户jonnocraig 在这个答案中所指出的,如果您为应用程序构建了一个容器并在Lambda上运行它,您可以克服这些限制。

票数 42
EN

Stack Overflow用户

发布于 2021-02-17 13:59:19

如果有人在2020年12月后偶然发现这个问题,那么AWS已经进行了一次重大的更新,以支持Lambda函数作为容器映像(最高可达10 up!!)。更多信息这里

票数 20
EN

Stack Overflow用户

发布于 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/

在高层次上,这些变化包括:

  1. 创建和安装EFS文件系统
  2. 在lambda函数中使用EFS
  3. 在EFS接入点内安装pip依赖项
  4. 设置PYTHONPATH环境变量以指示在何处查找依赖项
票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54632009

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档