aws cloudformation lambda python bad handler
Solution 1
Yes, thank you for your helps. That fixed it. I think AWS should have this in their documentation so other people can see it clearly. This is what I did.
"Handler": "simple_python_filename.lambda_handler",
"Code": {
"S3Bucket": "mybuckname",
"S3Key": "simple_python.zip"
where my zip file is "simple_python.zip". My file name in the zip file is "simple_python_filename.py". My function in the py file is "lambda_hander". Also, make sure you place the .py files in the root of the zip file.
Solution 2
I think the problem is with your declaration for "Handler".
It should contain the module name as well as the function name, i.e. it should be module_name.lambda_handler, where module_name is the name of the file containing your handler function.
I had the same error when creating lambda functions using boto3 for python - this solved the issue for me.
Solution 3
If you are coming here because you saw the error in the image I've posted, the fix is to prepend lambda_function
to the name of your handler in the Handler field of the AWS Lambda code screen.
For instance if your handler name in your code is lambda_handler
, You have to use lambda_function.lambda_handler
in the Handler field on your code screen.
This just means the default module name assigned to your python lambda function is as you guessed lambda_function
.
Related videos on Youtube
YLam
Updated on June 07, 2022Comments
-
YLam almost 2 years
I need to create aws Lambda (python) from cloudformation. The lambda function was created, but when I tried to execute the lambda, I keep getting the following error. I have tried many ways and I just couldn't get it working.
{ "errorMessage": "Bad handler 'lambda_handler'" }
This is how I created the lambda from cloudformation.
- Create a simple python hello program that contains print statement (as simple as possible)
Code:
def lambda_handler(): print('lambda_handler is called...'); print('Lambda is printing...');
Zip the python and place it in S3. (I have tried both folder and no folder)
Create a cloudformation template with the following resource.
JSON:
"Resources": { "LF1ZOLJ": { "Type": "AWS::Lambda::Function", "Properties": { "Handler": "lambda_handler", "Code": { "S3Bucket": "mybuckname", "S3Key": "simplepython.zip" }, "Description": "cfn-create-lambda", "Role": "arn:aws:iam::305760000000:role/lambda_basic_execution", "Runtime": "python2.7", "Timeout": 60 }, "Metadata": { "AWS::CloudFormation::Designer": { "id": "xxxxxxxxxxxxxxxxxxxxxxxx" } } } }
Go to Cloudformation and create a stack using the template. Stack was created successfully.
When I Test the lambda using "Hello World" event template. I get the error.
"errorMessage": "Bad handler 'lambda_handler'"
If I look at the CloudWatch Log I see
Bad handler 'lambda_handler': need more than 1 value to unpack.
I am not passing arguments. This is the "Hello World" lambda function in Python. If I create this lambda function manually in the Lambda service, I could execute it without any errors. I only get this error when I create the lambda using Cloudformation.
Please point me to the right direction. Thanks in advance.
-
Juan almost 4 yearsthis was exaclty my problem, it applies to terraform as well, handler field for aws_lambda_function object. The format is lambda_function_name.name_of_the_function_on_the_file
-
alex almost 3 yearsthis was my problem as well. My lambda handler lives in a different file though called
app
so for me it wasapp.lambda_handler