Module initialization error

I am using virtualenv and serverless-python-requirements for my Python deployment in AWS Lambda using serverless framework. But after upload when i am calling the function it is giving “module initialization error: [Errno 22] Invalid argument” error.

@himadri Can you paste a longer portion of the stack trace? Hard to tell what the issue is there.

Hi,

Thanks for replying. But I am not getting any other details in CloudWatch.

Can you please guide what to do.

There should be additional logs in CloudWatch or something. If not, you could paste your serverless.yml and function code in an attempt to reproduce?

Here is my serverless.yml file https://gist.github.com/himadriganguly/f9571c09a3c01c79ebf920034f5e5e55

Since you’re zipping your dependencies, do you have the line to unzip them at the top of your handler.py module?

# handler.py

import unzip_requirements

... rest of code ...

It’s going to be tough to debug without a longer stack trace or your function code.

1 Like

Yes included that like this import unzip_requirements.

So what can be the problem? What other things should I check?

Also checked my Python version under virtualenv which is Python 3.6.2.

Before using Serverless when I am manually creating the zip file with all the python modules in the root path and uploading it to Lambda it is working fine. To automate the process I am using the Serverless Framework and now I got into this problem. :disappointed: