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.