error, "Unable to import module 'lambda_function': No module named 'requests'"

0

I have written an AWS Lambda function in Python which uses the 'requests' library (and so has the line 'import requests').

When I test it, I get the error, "Unable to import module 'lambda_function': No module named 'requests'".

I have zipped the 'requests' library folder and the 'requests-2.31.0.dist-info folder' into an archive and have uploaded this to a new AWS layer within the AWS console and have then added the layer to my function, but I still get the error.

Any idea what I've done wrong or missed?

DivZero
질문됨 7달 전1249회 조회
2개 답변
1

Hi,

While creating the lambda layer zipped file, please make sure you zipped the content of the folder with the code, and not the folder itself [1].
Furthermore, please follow this troubleshooting guide [2].

References:
[1] https://stackoverflow.com/questions/71163939/aws-lambda-layer-unable-to-import-module-lambda-function-no-module-named-pya
[2] https://repost.aws/knowledge-center/lambda-import-module-error-python

Thanks,
Atul

profile picture
답변함 7달 전
0

Hi,

please make sure that the AWS Lambda layer that you created has the required folder structure, see https://docs.aws.amazon.com/lambda/latest/dg/packaging-layers.html.

Specifically, that the distro folder is within the python folder.

profile pictureAWS
전문가
답변함 7달 전
  • Hi Ben, Thanks for your reply but I am very new to this, so it's no clearer yet. I am using the AWS console to create the layer and upload the zip file. I haven't seen a folder structure and just assumed that doing it this way would result in the layer being created in the right place. How can I view and edit the folder structure?

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인