首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用无服务器框架部署AWS Lambda时缺少依赖关系

使用无服务器框架部署AWS Lambda时缺少依赖关系
EN

Stack Overflow用户
提问于 2020-11-16 09:09:00
回答 1查看 679关注 0票数 0

我试图使用无服务器框架将预测Lambda处理程序部署到AWS,我的代码的依赖项是py手电筒和转换器(HF)。

我正面临着这个问题,不知道如何克服同样的问题,

我已经正确配置了requirements.txt文件,它有以下2行,

代码语言:javascript
复制
transformers==2.10
https://download.pytorch.org/whl/cpu/torch-1.5.0%2Bcpu-cp38-cp38-linux_x86_64.whl

当我尝试使用“无服务器部署”命令时,有时它会创建一个包,其中包含包中requirements.zip中的所有依赖项,大约为144 MB,--这是预期的结果。

供您参考的日志

代码语言:javascript
复制
C:\Users\Rajeshwaranp\serverless-HFT>sls deploy
Serverless: Deprecation warning: Starting with next major version, API Gateway naming will be changed from "{stage}-{service}" to "{service}-{stage}".
            Set "provider.apiGateway.shouldStartNameWithService" to "true" to adapt to the new behavior now.
            More Info: https://www.serverless.com/framework/docs/deprecations/#AWS_API_GATEWAY_NAME_STARTING_WITH_SERVICE
Serverless: Adding Python requirements helper...
Serverless: Generated requirements from C:\Users\Rajeshwaranp\serverless-HFT\requirements.txt in C:\Users\Rajeshwaranp\serverless-HFT\.serverless\requirements.txt...
Serverless: Installing requirements from C:\Users\Rajeshwaranp\serverless-HFT\cache\72130b8b1c12a9cc09719c938b787b829ceb78a73eeafa251ccf974d7dafec58_slspyc\requirements.txt ...
Serverless: Docker Image: lambci/lambda:build-python3.8
Serverless: Using download cache directory C:\Users\Rajeshwaranp\serverless-HFT\cache\downloadCacheslspyc
Serverless: Running docker run --rm -v C\:/Users/Rajeshwaranp/serverless-HFT/cache/72130b8b1c12a9cc09719c938b787b829ceb78a73eeafa251ccf974d7dafec58_slspyc\:/var/task\:z -v C\:/Users/Rajeshwaranp/serverless-HFT/cache/downloadCacheslspyc\:/var/useDownloadCache\:z -u 0 lambci/lambda\:build-python3.8 python -m pip install -t /var/task/ -r /var/task/requirements.txt --cache-dir /var/useDownloadCache...
Serverless: Zipping required Python packages...
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Removing Python requirements helper...
Serverless: Injecting required Python packages to package...
Serverless: WARNING: Function predict_answer has timeout of 60 seconds, however, it's attached to API Gateway so it's automatically limited to 30 seconds.
Serverless: Creating Stack...
Serverless: Checking Stack create progress...
........
Serverless: Stack create finished...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service serverless-hft.zip file to S3 (144.02 MB)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
.................................
Serverless: Stack update finished...

但有时,当我使用相同的命令进行部署时,它会创建一个128 to (大约)的包,而包中的requirements.zip文件中没有任何依赖项。

供你参考的日志,

代码语言:javascript
复制
C:\Users\Rajeshwaranp\serverless-HFT>sls deploy
Serverless: Deprecation warning: Starting with next major version, API Gateway naming will be changed from "{stage}-{service}" to "{service}-{stage}".
            Set "provider.apiGateway.shouldStartNameWithService" to "true" to adapt to the new behavior now.
            More Info: https://www.serverless.com/framework/docs/deprecations/#AWS_API_GATEWAY_NAME_STARTING_WITH_SERVICE
Serverless: Adding Python requirements helper...
Serverless: Generated requirements from C:\Users\Rajeshwaranp\serverless-HFT\requirements.txt in C:\Users\Rajeshwaranp\serverless-HFT\.serverless\requirements.txt...
Serverless: Using static cache of requirements found at C:\Users\Rajeshwaranp\serverless-HFT\cache\72130b8b1c12a9cc09719c938b787b829ceb78a73eeafa251ccf974d7dafec58_slspyc ...
Serverless: Zipping required Python packages...
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Removing Python requirements helper...
Serverless: Injecting required Python packages to package...
Serverless: WARNING: Function predict_answer has timeout of 60 seconds, however, it's attached to API Gateway so it's automatically limited to 30 seconds.
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service serverless-hft.zip file to S3 (124.15 KB)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
..............
Serverless: Stack update finished...

那为什么会发生这种事?如何调整部署命令,以便始终包含依赖项?

EN

回答 1

Stack Overflow用户

发布于 2020-11-16 10:00:10

使用lambda层打包所有需求,确保requirements.txt文件中有所有需求。

只有在插件部分列出无服务器-python-requirements插件时,这才能起作用。用这个替换您的自定义键,并为需要这些需求的函数提供使用该层的引用。

代码语言:javascript
复制
plugins:
  - serverless-python-requirements
custom:
  pythonRequirements:
    layer: true
functions:
  auth:
    handler: data.auth
    layers:
      - { Ref: PythonRequirementsLambdaLayer}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64855191

复制
相关文章

相似问题

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