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

2024-10-01 15:48:36 发布

您现在位置:Python中文网/ 问答频道 /正文

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

创建使用相同依赖项的类似函数后,我将依赖项从函数中分离出来,并使用pip3和setup.py构建它们。当运行pip3列表时,我可以看到预期的包。为了使用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理解的一个问题,因此打开的问题可能不相关


Tags: lambda函数buildenvevent图层jsonlocal

热门问题