跳至內容

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.

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。