“Unable to import module ‘lambda_function’: No module named ‘msgspec._core’,”

huangapple go评论77阅读模式
英文:

"Unable to import module 'lambda_function': No module named 'msgspec._core'",

问题

抱歉,我无法理解你的请求。请提供一个明确的问题或指示,我将尽力帮助你。

英文:

I am trying to include a python library in AWS lambda as a layer. The library is included but the interpreter is not identifying file msgspec._core. It gives the following error. I am using python version 3.9. I did try python version 3.8 as well but got the same error.

> Response { "errorMessage": "Unable to import module
> 'lambda_function': No module named 'msgspec._core'",
"errorType":
> "Runtime.ImportModuleError", "requestId":
> "ab9ed15b-2312-4204-985e-bc8cf1566c6b", "stackTrace": [] }
>
> Function Logs START RequestId: ab9ed15b-2312-4204-985e-bc8cf1566c6b
> Version: $LATEST [ERROR] Runtime.ImportModuleError: Unable to import
> module 'lambda_function': No module named 'msgspec._core' Traceback
> (most recent call last):END RequestId:
> ab9ed15b-2312-4204-985e-bc8cf1566c6b REPORT RequestId:
> ab9ed15b-2312-4204-985e-bc8cf1566c6b Duration: 20.25 ms Billed
> Duration: 21 ms Memory Size: 128 MB Max Memory Used: 55 MB Init
> Duration: 347.62 ms
>
> Request ID ab9ed15b-2312-4204-985e-bc8cf1566c6b

I will be very thankful for your help.

答案1

得分: 1

尝试将代码与所需的模块一起打包成一个 .zip 文件,并部署到 AWS Lambda。你可以使用 VS Code 的 AWS 扩展直接将代码和所需内容部署到 AWS Lambda。

由于你正在使用 Python 3.9,而 AWS 使用的是 Linux,你应该按照以下步骤进行操作:

  1. 从 pypi 下载适用于该平台(py 3.9 和 linux x86_64)的 msgspec.whl 文件。以下是链接:

msgspec.whl

可以在这里找到其他 Python 版本(x86_64.manylinux)的文件 -
https://pypi.org/project/msgspec/#files

  1. 将文件下载到你本地存放 Lambda 代码的目录中。

  2. 然后在你的计算机上安装 wheel 并解压刚刚下载的文件。

pip install wheel
wheel unpack <wheel_file_name>
  1. 现在将整个目录压缩并部署到 Lambda 函数中。
英文:

Try to deploy the code along with the required modules as a .zip file to aws lambda.
You can use VS Code's AWS extension to directly deploy your code and requirements onto aws lambda.

As you're using Python 3.9 and aws uses linux you should follow the below steps:
Download the msgspec.whl file for the above platform (py 3.9 and linux x86_64) from pypi. Here's the link :

msgspec.whl

Find other python versions here (x86_64.manylinux) -
https://pypi.org/project/msgspec/#files

Download the file in the directory where your lambda code is present(locally).

Then install wheel on your pc and unpack the file you just downloaded.

pip install wheel
wheel unpack &lt;wheel_file_name&gt;

Now zip the entire directory and deploy it to the lambda function.

huangapple
  • 本文由 发表于 2023年2月8日 17:25:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/75383630.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定