Aws cloudformation lambda python bad handler

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 tried many ways and I just couldn't get it to work.

{
  "errorMessage": "Bad handler 'lambda_handler'"
}

This is how I created the lambda from the clouds.

  • Create a simple python welcome program containing a print statement (as simple as possible)

the code:

def lambda_handler():
    print('lambda_handler is called...');
    print('Lambda is printing...');
  1. Replace the python and place it in S3. (I tried both the folder and the folder)

  2. Create a cloud information 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"
      }
    }
  }
}
  1. Go to Cloudformation and create a stack using the template. The stack was created successfully.

  2. When I test lambda using Hello World event template. I get an error message.

"errorMessage": "Bad lambda_handler 'handler"

CloudWatch,

lambda_handler: 1 .

. "Hello World" Python. - Lambda, - . Cloudformation.

. .

+4
3

, . . , AWS , . , .

    "Handler": "simple_python_filename.lambda_handler",
    "Code": {
      "S3Bucket": "mybuckname",
      "S3Key": "simple_python.zip"

zip "simple_python.zip". zip - "simple_python_filename.py". py - "lambda_hander". , , .py zip .

+6

, "".

, , module_name.lambda_handler, module_name - , .

- boto3 python - .

+3

Image of AWS Lambda lambda_handler error screen

, , , , lambda_function AWS Lambda.

For example, if your handler name is in your code lambda_handler, you should use the lambda_function.lambda_handlerHandler field on the screen of your code.

It just means that the default module name assigned to your python lambda function, you guessed it lambda_function.

Image of the fix for the error above

+1
source

All Articles