admin管理员组文章数量:1122846
I used pip to install locally and the dependency installed here: c:\users\info\appdata\local\programs\python\python312\lib\site-packages\my-dependency
I zipped the my-dependency folder and called it the same name my-dependency.zip
I created a new lambda layer and added it to my lambda function.
However, when I test my function, I get:
"errorMessage": "Unable to import module 'lambda_function': No module named 'my-dependency'"
I see other posts about how to include the dependency in the package I upload with my code, but my code is directly in the console and do not upload it.
I used pip to install locally and the dependency installed here: c:\users\info\appdata\local\programs\python\python312\lib\site-packages\my-dependency
I zipped the my-dependency folder and called it the same name my-dependency.zip
I created a new lambda layer and added it to my lambda function.
However, when I test my function, I get:
"errorMessage": "Unable to import module 'lambda_function': No module named 'my-dependency'"
I see other posts about how to include the dependency in the package I upload with my code, but my code is directly in the console and do not upload it.
Share Improve this question asked Nov 21, 2024 at 20:19 PrimicoPrimico 2,4154 gold badges31 silver badges40 bronze badges1 Answer
Reset to default 1https://docs.aws.amazon.com/lambda/latest/dg/python-layers.html
The issue occurs because AWS Lambda cannot locate the module from the Lambda layer you’ve created. The likely cause is the Directory structure of the zipped layer: The Python dependencies in the zip file must be in the correct directory structure (python/lib/python3.x/site-packages/) for Lambda to recognize them.
my-dependency.zip
└── python/
└── lib/
└── python3.x/
└── site-packages/
└── my-dependency/
Replace python3.x with the Python version used by your Lambda runtime (e.g., python3.9 for Python 3.9 runtime). To create the correct structure for you case, you can simply follow these steps, just update the python version X:
mkdir -p python/lib/python3.x/site-packages
cp -r c:/users/info/appdata/local/programs/python/python312/lib/site-packages/my-dependency python/lib/python3.x/site-packages/
zip -r my-dependency.zip python/
本文标签:
版权声明:本文标题:amazon web services - How to add dependency to AWS lambda layer when code is in console, not uploaded - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736307413a1933303.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论