Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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()
like image 238
user630702 Avatar asked Sep 13 '25 17:09

user630702


2 Answers

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.

like image 95
Ermiya Eskandary Avatar answered Sep 15 '25 06:09

Ermiya Eskandary


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"]
like image 36
waterproof Avatar answered Sep 15 '25 06:09

waterproof