Home > Blockchain >  Unable to import module 'lambda_function':
Unable to import module 'lambda_function':

Time:12-04

When I am trying to test my python code on AWS Lambda I am getting the following error.

Response
{
  "errorMessage": "Unable to import module 'lambda_function': No module named 'lambda_function'",
  "errorType": "Runtime.ImportModuleError",
    "stackTrace": []
}

These are the basic Setup steps which I followed to push my code into AWS Lambda:-

  • First rename your main.py file as 'lambda_function.py'
  • Change the name of your 'main' function to 'def lambda_handler():'
  • ZIP the File
  • Go to AWS Lambda Console, Create Function.
  • Provide the FunctionName - 'Demo'
  • Choose Python 3.9 Runtime (or 3.7/3.8)
  • Let the architecture be 'x86_64'
  • Rest configurations be acceptable. Hit the 'Create Function' Button
  • There will be a tab/dropdown named 'Upload From'
  • Choose the .zip File
  • Upload the File
  • Click on the 'Test Button'
  • Click the configure test event.
  • Provide the event name as 'Test'
  • Clear the JSON Values and provide empty JSON- {}
  • Save it.
  • Test the Lambda Function

But after doing this I am getting this error

"errorMessage": "Unable to import module 'lambda_function': No module named 'lambda_function'",
  "errorType": "Runtime.ImportModuleError",

I have made sure to check my enter image description here

Directory Structure of my zip File:

enter image description here

CodePudding user response:

Your lambda_function.py is in a subfolder called AWS_REPORT.... So you have the tell that to aws. The hendler info should be:

AWS_REPORT.../lambda_function.lambda_handler

Off course AWS_REPORT... must be replaced by the actual name.

  • Related