如何增加AWS lambda部署程序包(RequestEntityTooLargeException)的最大大小? [英] How to increase the maximum size of the AWS lambda deployment package (RequestEntityTooLargeException)?

查看:90
本文介绍了如何增加AWS lambda部署程序包(RequestEntityTooLargeException)的最大大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I upload my lambda function sources from AWS codebuild. My Python script uses NLTK so it needs a lot of data. My .zip package is too big and an RequestEntityTooLargeException occurs. I want to know how to increase the size of the deployment package sent via the UpdateFunctionCode command.

我使用 AWS CodeBuild 将源从GitHub存储库转换为 AWS Lambda .这是相关的buildspec文件:

I use AWS CodeBuild to transform the source from a GitHub repository to AWS Lambda. Here is the associated buildspec file:

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软件包中的数据太多.请参阅下面的构建日志:

When I launch the pipeline, I have RequestEntityTooLargeException because there are too many data in my .zip package. See the build logs below:

[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 软件包.

Everything works correctly when I reduce the NLTK data to download (I tried with only the packages stopwords and wordnet.

有人有解决这个尺寸限制问题"的想法吗?

Does anyone have an idea to solve this "size limit problem"?

推荐答案

您不能增加Lambda的部署程序包大小. AWS Lambda开发人员指南中介绍了AWS Lambda限制.有关这些限制的工作原理的更多信息,请参见此处.本质上,您解压缩的程序包大小必须小于250MB(262144000字节).

You cannot increase the deployment package size for Lambda. AWS Lambda limits are described in AWS Lambda devopler guide. More information on how those limits work can be seen here. In essence, your unzipped package size has to be less than 250MB (262144000 bytes).

PS:使用图层并不能解决调整大小的问题,尽管有助于管理和升级.也许更快的冷启动.程序包的大小包括各层- Lambda层.

PS: Using layers doesn't solve sizing problem, though helps with management & maybe faster cold start. Package size includes the layers - Lambda layers.

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

A function can use up to 5 layers at a time. The total unzipped size of the function and all layers can't exceed the unzipped deployment package size limit of 250 MB.

这篇关于如何增加AWS lambda部署程序包(RequestEntityTooLargeException)的最大大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆