猿问

执行函数时无法从 AWS 层切换到指定本地构建的可编辑 pip3 包

我正在学习 python 并尝试构建多个 lambdas 来存储和处理 Spotify 收听历史。我最初编写了一个 lambda,所有依赖项打包在同一个目录中,并使用相对路径导入。


一旦创建了使用相同依赖项的类似函数,我就将依赖项从函数中分离出来,并使用 pip3 和 setup.py 构建它们。运行 pip3 list 时,我可以按预期看到包。为了使用本地执行函数sam build && sam local invoke SpotifyPlayHistoryListener --env-vars env.json --event events/event.json并验证成功,我指定了一个我已经构建的层——这行得通!


为了避免重建图层和修改我的功能,我希望能够恢复使用 requirements.txt 文件并删除指定的图层。


重现问题的步骤:


Build local editable package - pip3 install -e .

Specify in requirements.txt

sam build && sam local invoke SpotifyPlayHistoryListener --env-vars env.json --event events/event.json

观察结果:


Building resource 'SpotifyPlayHistoryListener'

Running PythonPipBuilder:ResolveDependencies

Build Failed

Error: PythonPipBuilder:ResolveDependencies - Could not satisfy the requirement: spotify-client

预期结果:


构建成功并且函数成功执行。


其他环境详细信息:


sam build && sam local invoke SpotifyPlayHistoryListener --env-vars env.json --event events/event.json使用层指定依赖项时,我可以在本地执行该函数


我创建了以下问题https://github.com/awslabs/aws-lambda-builders/issues/155。我认为这可能是我对 python 和 pip 的理解的问题,因此打开的问题可能不相关。


月关宝盒
浏览 107回答 1
1回答

DIEA

由于我的依赖项没有发布到 pypi,我需要修改 require.txt 中的条目以使用包的实际文件路径。
随时随地看视频慕课网APP

相关分类

Python
我要回答