简体   繁体   English

使用无服务器框架将 Python package 部署到 AWS lambda 时出错

[英]Error deploying Python package to AWS lambda using Serverless framework

I've followed this tutorial from the serverless website to try deploy my first AWS lambda function with a package dependency.我按照无服务器网站上的教程尝试部署我的第一个 AWS lambda function 和 package 依赖项。

The error I get is STDERR: ERROR: Invalid requirement: '��' (from line 1 of /var/task/requirements.txt) I haven't been able to find a solution on using google.我得到的错误是STDERR: ERROR: Invalid requirement: '��' (from line 1 of /var/task/requirements.txt)我无法找到使用谷歌的解决方案。 Having tried to go through the tutorial various times the same error keeps reoccurring, sometimes as ERROR: Invalid requirement: '\x00' or ERROR: Invalid requirement: '\x00\x01' or something similar.通过本教程多次尝试 go 后,相同的错误不断重复出现,有时是ERROR: Invalid requirement: '\x00'ERROR: Invalid requirement: '\x00\x01'或类似的错误。 It seems to me that the serverless-python-requirements plugin is formatting it's own requirement file incorrectly, but I just don't know.在我看来,serverless-python-requirements 插件错误地格式化了它自己的需求文件,但我只是不知道。

My requirements.txtwhen I have no dependencies is empty, which then translates to a serverless generated.serverless\requirements.txt:当我没有依赖项时,我的 requirements.txt 为空,然后转换为无服务器生成的.serverless\requirements.txt:

�� ��

When my requirements.txt is当我的 requirements.txt 是

numpy==1.19.2 numpy==1.19.2

this translates to a.serverless/requirements.txt as follows:这转化为 a.serverless/requirements.txt 如下:

��numpy = = 1. 1 9. 2 ��numpy = = 1. 1 9. 2

I have gone through each step of the tutorial, and have not run into any problems until I run serverless deploy .我已经完成了教程的每个步骤,并且在运行serverless deploy之前没有遇到任何问题。 This is the stack trace I get:这是我得到的堆栈跟踪:

Serverless: Invoke deploy
Serverless: Invoke package
Serverless: Invoke aws:common:validate
Serverless: Invoke aws:common:cleanupTempDir
Serverless: Generated requirements from C:\Users\...\Documents\Serverless\my\requirements.txt in C:\Users\...\Documents\Serverless\my\.serverless\requirements.txt...
Serverless: Installing requirements from C:\Users\...\AppData\Local\UnitedIncome\serverless-python-requirements\Cache\943a69dded6372ca37aaaacaf21570a18766193003231d5130a067451373395d_slspyc\requirements.txt ...
Serverless: Docker Image: lambci/lambda:build-python3.8
Serverless: Trying bindPath C:/Users/.../AppData/Local/UnitedIncome/serverless-python-requirements/Cache/943a69dded6372ca37aaaacaf21570a18766193003231d5130a067451373395d_slspyc (run,--rm,-v,C:/Users/.../AppData/Local/UnitedIncome/serverless-python-requirements/Cache/943a69dded6372ca37aaaacaf21570a18766193003231d5130a067451373395d_slspyc:/test,alpine,ls,/test/requirements.txt)
Serverless: /test/requirements.txt
Serverless: Using download cache directory C:\Users\...\AppData\Local\UnitedIncome\serverless-python-requirements\Cache\downloadCacheslspyc
Serverless: Trying bindPath C:/Users/.../AppData/Local/UnitedIncome/serverless-python-requirements/Cache/downloadCacheslspyc (run,--rm,-v,C:/Users/.../AppData/Local/UnitedIncome/serverless-python-requirements/Cache/downloadCacheslspyc:/test,alpine,ls,/test/requirements.txt)
Serverless: /test/requirements.txt
Serverless: Running docker run --rm -v C\:/Users/.../AppData/Local/UnitedIncome/serverless-python-requirements/Cache/4870b1f009d955f0e7d5138512661e3ec4364d6a9c1e3c6cadc9d51a7e3b8dd2_slspyc\:/var/task\:z -v C\:/Users/.../AppData/Local/UnitedIncome/serverless-python-requirements/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...

  Error --------------------------------------------------

  Error: STDOUT:

  STDERR: ERROR: Invalid requirement: '��' (from line 1 of /var/task/requirements.txt)

      at C:\Users\...\Documents\Serverless\my\node_modules\serverless-python-requirements\lib\pip.js:325:13
      at Array.forEach (<anonymous>)
      at installRequirements (C:\Users\...\Documents\Serverless\my\node_modules\serverless-python-requirements\lib\pip.js:312:28)
      at installRequirementsIfNeeded (C:\Users\...\Documents\Serverless\my\node_modules\serverless-python-requirements\lib\pip.js:556:3)
      at ServerlessPythonRequirements.installAllRequirements (C:\Users\...\Documents\Serverless\my\node_modules\serverless-python-requirements\lib\pip.js:635:29)
  From previous event:
      at PluginManager.invoke (C:\Users\...\AppData\Roaming\npm\node_modules\serverless\lib\classes\PluginManager.js:498:22)
      at PluginManager.spawn (C:\Users\...\AppData\Roaming\npm\node_modules\serverless\lib\classes\PluginManager.js:518:17)
      at C:\Users\...\AppData\Roaming\npm\node_modules\serverless\lib\plugins\deploy\deploy.js:122:50
  From previous event:
      at Object.before:deploy:deploy [as hook] (C:\Users\...\AppData\Roaming\npm\node_modules\serverless\lib\plugins\deploy\deploy.js:102:22)
      at C:\Users\...\AppData\Roaming\npm\node_modules\serverless\lib\classes\PluginManager.js:498:55
  From previous event:
      at PluginManager.invoke (C:\Users\...\AppData\Roaming\npm\node_modules\serverless\lib\classes\PluginManager.js:498:22)
      at C:\Users\...\AppData\Roaming\npm\node_modules\serverless\lib\classes\PluginManager.js:533:24
  From previous event:
      at PluginManager.run (C:\Users\...\AppData\Roaming\npm\node_modules\serverless\lib\classes\PluginManager.js:533:8)
      at C:\Users\...\AppData\Roaming\npm\node_modules\serverless\lib\Serverless.js:168:33
  From previous event:
      at Serverless.run (C:\Users\...\AppData\Roaming\npm\node_modules\serverless\lib\Serverless.js:155:74)
      at C:\Users\...\AppData\Roaming\npm\node_modules\serverless\scripts\serverless.js:50:26
      at processImmediate (internal/timers.js:456:21)
  From previous event:
      at Object.<anonymous> (C:\Users\...\AppData\Roaming\npm\node_modules\serverless\scripts\serverless.js:50:4)
      at Module._compile (internal/modules/cjs/loader.js:1137:30)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
      at Module.load (internal/modules/cjs/loader.js:985:32)
      at Function.Module._load (internal/modules/cjs/loader.js:878:14)
      at Module.require (internal/modules/cjs/loader.js:1025:19)
      at require (internal/modules/cjs/helpers.js:72:18)
      at Object.<anonymous> (C:\Users\...\AppData\Roaming\npm\node_modules\serverless\bin\serverless.js:47:1)
      at Module._compile (internal/modules/cjs/loader.js:1137:30)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
      at Module.load (internal/modules/cjs/loader.js:985:32)
      at Function.Module._load (internal/modules/cjs/loader.js:878:14)
      at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
      at internal/main/run_main_module.js:17:47

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com

  Your Environment Information ---------------------------
     Operating System:          win32
     Node Version:              12.18.4
     Framework Version:         2.1.1
     Plugin Version:            4.0.4
     SDK Version:               2.3.2
     Components Version:        3.1.3

Fix:使固定:

  • Converting the requirements.txt to UTF8 will fix this issue.requirements.txt转换为 UTF8 将解决此问题。 (tested on linux) (在linux上测试过)
  • Try converting requirements.txt to ASCII.尝试将requirements.txt转换为 ASCII。

This is the problem with requirements.txt file encoding.这是 requirements.txt 文件编码的问题。

Detailed explanation详细解释

This is an open issue as on date 10th March 2022这是截至 2022 年 3 月 10 日的未决问题

The serverless plugin rewrites the file into .serverless directory & it assumes UTF8 encoding when it reads the file.无服务器插件将文件重写到.serverless目录中,并在读取文件时采用 UTF8 编码。

The problem occurs as serverless attempts to read a file with another encoding & then dump it into .serverless folder.当无服务器尝试使用另一种编码读取文件,然后将其转储到.serverless文件夹时,就会出现问题。

Serverless-python-requirements issue Serverless-python-requirements 问题

Add dockerizePip command at the end then it will not show this error在末尾添加 dockerizePip 命令,然后它不会显示此错误

custom:
  wsgi:
    app: handler.app
    pythonBin: python # Some systems with Python3 may require this
    packRequirements: false
  pythonRequirements:
    dockerizePip: non-linux

or delete the requirements.txt then enter serverless deploy and then paste requirements.txt and run again serverless deploy或删除 requirements.txt 然后输入 serverless deploy 然后粘贴 requirements.txt 并再次运行 serverless deploy

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过无服务器框架部署到 AWS Lambda 时,将 Package 文件放入应用程序包的特定文件夹 - Package files into specific folder of application bundle when deploying to AWS Lambda via Serverless Framework 带有 AWS Lambda 错误“找不到模块”的无服务器框架 - Serverless Framework with AWS Lambda error "Cannot find module" 如何使用无服务器工具在 AWS lambda 上安装 librdKafka package - How to install librdKafka package on AWS lambda using serverless tool 无服务器 AWS Lambda CORS 错误 - Serverless AWS Lambda CORS Error 有没有办法在不使用无服务器离线的情况下调试部署到 AWS Lambda 的无服务器框架 Typescript 函数? - Is there a way to debug Serverless Framework Typescript functions deployed to AWS Lambda, without using serverless-offline? 使用无服务器框架在 lambda AWS 中授予授权代码 - Authorization code grant in lambda AWS with Serverless Framework AWS Lambda function on Java with Serverless framework and GraalVM - AWS Lambda function on Java with Serverless framework and GraalVM 无服务器 AWS Lambda 层与 python 包不工作。 奇怪的 hash 添加到 package 名称 - Serverless AWS Lambda Layer with python packages not working. Weird hash added to package name AWS lambda 无服务器中不存在此类文件错误 - AWS lambda no such file exists error in serverless 在等待数据库查询之前返回 AWS Lambda 响应 - 无服务器框架 - Returning AWS Lambda response before waiting for DB query - Serverless framework
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM