user630702
user630702

Reputation: 3097

Why do I get a "Bad handler AWS Lambda - not enough values to unpack" error?

I'm trying to execute a Lambda function but I get the following error:

{
  "errorMessage": "Bad handler 'AlertMetricSender': not enough values to unpack (expected 2, got 1)",
  "errorType": "Runtime.MalformedHandlerName",
  "stackTrace": []
}

My Lambda handler is specified in AlertMetricSender.py:

from modules.ZabbixSender import ZabbixSender
def lambda_handler(event, context):
    sender = ZabbixSender("10.10.10.10", 10051)
    sender.add("Zabbix server", "lambda.test", 5.65)
    sender.send()

Upvotes: 21

Views: 20710

Answers (2)

waterproof
waterproof

Reputation: 5174

If you're using Docker & Submodules

In my case, I'm using a custom-built docker image, and my handler is inside of a submodule.

This is what I had originally at the bottom of my Dockerfile:

ENTRYPOINT [ "python", "-m", "awslambdaric" ]
CMD ["parent_module.main.lambda_handler"]

Instead of a python-style import path (<parent_module>.<sub_module>.<function_name>), the CMD format is actually <filepath>.<function_name>. That means the parent module and child module need to be separated by a /, not a .. This is what worked for me:

ENTRYPOINT [ "python", "-m", "awslambdaric" ]
CMD ["parent_module/main.lambda_handler"]

Upvotes: 1

Ermiya Eskandary
Ermiya Eskandary

Reputation: 23592

This is normally caused by an incorrect value specified for the "Handler" setting for the Lambda function.

It is a reference to the method in your function code that processes events i.e. the entry point.

enter image description here

The value of the handler argument is comprised of the below, separated by a dot:

  • The name of the file in which the Lambda handler function is located
  • The name of the Python handler function.

Make sure you have not missed the filename.

In this case, it looks like the handler should be set to AlertMetricSender.lambda_handler.

Upvotes: 33

Related Questions