Hello lad
Hello lad

Reputation: 18790

AWS Lambda Python: 'handler' missing on module

I have a deployment package in the following structure:

my-project.zip
    --- my-project.py
    ------ lambda_handler()

Then I define the handler path in configuration file

my-project.lambda_handler

Get the error:

'handler' missing on module

Can not understand that

Upvotes: 14

Views: 39247

Answers (3)

G. Shand
G. Shand

Reputation: 468

While not specific to your provided example, this error can occur for another reason as well -- naming conflicts with standard library modules.

E.g. if I have the following package structure, and specify my handler as email.handler, there will be a collision with the standard library email package and a similar error will be raised: handler missing on module 'email'

my-project.zip
    --- email.py
    ------ handler()

Upvotes: 0

jsims281
jsims281

Reputation: 2206

I had this issue and had to make sure I had a function called handler in my file, e.g.:

# this just takes whatever is sent to the api gateway and sends it back

def handler(event, context):
    try:
        return response(event, 200)
    except Exception as e:
        return response('Error' + e.message, 400)

def response(message, status_code):
    return message

Upvotes: 3

SkyWalker
SkyWalker

Reputation: 29150

There are some issues occurring this error.

Issue#1:

The very first issue you’re gonna run into is if you name the file incorrectly, you get this error:

Unable to import module 'lambda_function': No module named lambda_function

If you name the function incorrectly you get this error:

Handler 'handler' missing on module 'lambda_function_file': 'module' object has no attribute 'handler'

On the dashboard, make sure the handler field is entered as function_filename.actual_function_name and make sure they match up in your deployment package.

If only the messages were a bit more instructive that would have been a simpler step.

Resource Link:

No lambda_function?

Issue#2:

adrian_praja has solved the issue in aws forum. He answered the following

I belive your index.js should contain

exports.createThumbnailHandler = function(event, context) {}

Issue#3:

Solution: Correctly specify the method call

This happens when the specification of the method called by node.js is incorrect in Lambda's setting. Please review the specification of the method to call.

In the case of the above error message, I attempted to call the handler method of index.js, but the corresponding method could not be found. The processing to call is set with "Handler" on the configuration tab. Below is an example of setting to call the handler method of index.js. enter image description here

Resource Link:

  1. http://qiita.com/kazuqqfp/items/ac8d93918d0030b31aad
  2. AWS Lambda Function is returning Handler 'handler' missing on module 'index'

Upvotes: 15

Related Questions