1

I'm trying to run a microservice on AWS Lambda and because it requires NumPy and pymysql dependencies I've followed the steps outlined here

I receive this error upon uploading the dependencies and code to S3 and trying to run my test functions.

Traceback (most recent call last):
  File "/var/runtime/awslambda/bootstrap.py", line 538, in <module>
    main()
  File "/var/runtime/awslambda/bootstrap.py", line 528, in main
    run_init_handler(init_handler, invokeid)
  File "/var/runtime/awslambda/bootstrap.py", line 94, in run_init_handler
    init_handler()
TypeError: 'module' object is not callable

Any ideas on what could have happened? It runs fine on both my EC2 instance and my local computer

Dennis Nguyen
  • 11
  • 1
  • 3
  • How do you deploy your function? Maybe you passed your module name instead of the handler function? – Ronyis Jul 06 '18 at 21:37

2 Answers2

1

Lambda now has "layers" which could / should help you with that now.

But for others in the future, I had the exact same problem.

I had just finished refactoring a single-file Lambda Python module to a set of files, which included init.py. Turns out that if you have a module named init.py sitting next to a __init__.py in a package, some part of the AWS bootstrap processes can't handle the import or errors relating to the import; whether the file is good during import (your function times out) or bad (the traceback above).

I renamed init.py to connect.py (because I'm only setting up connection information for on-demand connections), then stopped seeing OP's traceback, and was able to move on.

I haven't attempted to reproduce with variations on init*.py module names.

Very strange edge case to run into.

Josiah
  • 727
  • 5
  • 15
0

I also came across this in a serverless app and it turns out it was down to how the handler was defined in the serverless.yaml. The bootstrap will take this value and try to execute it. In my case it was not pointing to a function in my python file but was pointing to one of the modules within the file.

functions:
  some_lambda:
    handler: src/somefile.jwt

In somefile.py there was an import for jwt. Code was meant to call a func jwt_auth but ended up trying to call the jwt module, causing the error seen by the OP.

sgargan
  • 12,208
  • 9
  • 32
  • 38