Greengrass Python Lambda 使用 awsiotsdk:找不到'_awscrt'模块

0

【以下的问题经过翻译处理】 我正在尝试创建一个Greengrass Lambda函数,使用IoT SDK发布到IPC主题。我的Lambda代码包括:

from awsiot import greengrasscoreipc  # type: ignore
from awsiot.greengrasscoreipc.model import (  # type: ignore
    JsonMessage,
    PublishMessage,
    PublishToTopicRequest,
)

ipc_client = greengrasscoreipc.connect()

这导致了以下的导入错误:

FATAL: lambda_runtime.py:426,Failed to initialize Lambda runtime due to exception: No module named '_awscrt'.

我可以看到Lambda文件包括awscrtawsiot/greengrass/v2/packages/artifacts-unarchived/componentName/version/lambda-artifact/。因此,我不确定为什么导入失败。

我使用非固定的Python 3.8 Lambda在NoContainer模式下运行,并使用LambdaManager v2.2.3、LambdaLauncher v2.0.10和LambdaRuntimes v2.0.8

我已经能够在非Lambda组件中使用awsiot来发布到IPC主题。该组件在安装生命周期期间使用pip install -r requirements.txt命令安装awsiotsdkggc_user的site-packages中,而Lambda组件则包含其软件包依赖项一起交付到设备上。有什么想法需要我做不同的事情吗?我还没有看到其他具有不同依赖关系的Lambda的这个问题。

profile picture
专家
已提问 5 个月前17 查看次数
1 回答
0

【以下的回答经过翻译处理】 我认为这基本上是在面临同样的问题:https://repost.aws/questions/QUvlMRwS8sTYWi2-1Sav0kog/lambda-can-not-load-python-modules-installed-with-component

我打算尝试那里列出的一些解决方案,但首先我使Lambda和非Lambda组件的Python版本对齐。我使用这里提供的Dockerfile:https://github.com/aws-greengrass/aws-greengrass-docker

其中包括:

# Install Greengrass v2 dependencies
RUN yum update -y && yum install -y python37 tar unzip wget sudo procps which && \
    amazon-linux-extras enable python3.8 && yum install -y python3.8 java-11-amazon-corretto-headless && \

因此,Python3.7是系统默认版本,用于我的非Lambda组件,而Lambda组件正在使用Python3.8运行时。我更新了Dockerfile,以在所有地方使用3.8,将上述内容更改为:

RUN yum update -y  \
    && amazon-linux-extras install python3.8 \
    && update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1 \
    && update-alternatives --install /usr/bin/pip3 pip3 /usr/bin/pip3.8 1 \
    && yum install -y tar unzip wget sudo procps which \
    && yum install -y java-11-amazon-corretto-headless \

现在所有组件都在使用3.8。我已经有一个非Lambda组件,它通过pip安装awsiotsdk以供ggc_user使用。现在也使用awsiotsdk的新Lambda组件也能够从awsiot导入,毫无问题。我认为Lambda工件缺少的任何东西现在都从ggc_user站点包中启动,这类似于其他帖子中提到的解决方案。

对于我的使用情况来说,这很好,因为

profile picture
专家
已回答 5 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则