title: aws cloudformation lambda python bad handler
body: <p>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.</p>
  
  <pre><code>{
    "errorMessage": "Bad handler 'lambda_handler'"
  }
  </code></pre>
  
  <p>This is how I created the lambda from cloudformation.</p>
  
  <ol>
  <li>Create a simple python hello program that contains print statement (as simple as possible)</li>
  </ol>
  
  <p>Code:</p>
  
  <pre><code>def lambda_handler():
      print('lambda_handler is called...');
      print('Lambda is printing...');
  </code></pre>
  
  <ol start="2">
  <li><p>Zip the python and place it in S3. (I have tried both folder and no folder)</p></li>
  <li><p>Create a cloudformation template with the following resource.</p></li>
  </ol>
  
  <p>JSON:</p>
  
  <pre><code>"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"
        }
      }
    }
  }
  </code></pre>
  
  <ol start="4">
  <li><p>Go to Cloudformation and create a stack using the template. Stack was created successfully.</p></li>
  <li><p>When I Test the lambda using "Hello World" event template. I get the error.</p></li>
  </ol>
  
  <blockquote>
    <p>"errorMessage": "Bad handler 'lambda_handler'"</p>
  </blockquote>
  
  <p>If I look at the CloudWatch Log I see</p>
  
  <blockquote>
    <p>Bad handler 'lambda_handler': need more than 1 value to unpack.</p>
  </blockquote>
  
  <p>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.  </p>
  
  <p>Please point me to the right direction. Thanks in advance.</p>