跳至内容

Lambda with layers: Runtime.ImportModuleError: Unable to import module

0

The zip file structure looks as expected by lambda so not sure why I am getting this error. My lambda function is main-lambda.py and it directly at the root of the zip/folder structure - folder-structure Runtime config: Runtime Python 3.12 HandlerInfo main-lambda.lambda_handler ArchitectureInfo x86_64

Structure:- nupeacock-main-backend |nupeacock-backend-for-aws.zip | main-lambda.py

已提问 2 年前1360 查看次数

2 回答
1

Firstly, it appears that your lambda function code is nested inside the zip file/folder - which seems to be your library (nupeacock-backend-for-aws.zip)? Try moving your Lambda function code up to the root folder (nupeacock-main-backend) and run test again. It could be that your Lambda function code couldn't find the path to your library.

Secondly, you mentioned "layers", are your libraries deployed as Lambda Layer? Or you intend to just refer to your libraries as path-relative to your Lambda function as you did above?

已回答 2 年前

  • Yes, already tried it and it works now.

0

Hello,

Python 3.12 is based on an Amazon Linux 2023 Amazon Machine Image (AMI). So, create the layer on an Amazon Linux 2023 OS.

Follow this article to troubleshoot this error , https://repost.aws/knowledge-center/lambda-import-module-error-python

专家

已回答 2 年前

  • thank you for your response but the issue is with calling the main lambda handler function itself (which is correctly located in the root folder of zip) and not with dependencies so not sure I agree with your response.

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

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