lurscher
lurscher

Reputation: 26983

AWS Lambda package deployment

I'm trying to deploy a python .zip package as an AWS Lambda

I choose the hello-python Footprint.

I created the 1st lambda with the inline code, after that I tried to change to upload from a development .zip.

The package I used is a .zip contains a single file called hello_python.py with the same code as the default inline code sample, which is shown below:

from __future__ import print_function

import json

print('Loading function')


def lambda_handler(event, context):
    #print("Received event: " + json.dumps(event, indent=2))
    print("value1 = " + event['key1'])
    print("value2 = " + event['key2'])
    print("value3 = " + event['key3'])
    return event['key1']  # Echo back the first key value
    #raise Exception('Something went wrong')

After I click "save and test", nothing happens, but I get this weird red ribbon, but no other substantive error messages. The logs and the run results do not exhibit any change if modifying to source, repackaging and uploading it again.enter image description here

Upvotes: 2

Views: 4123

Answers (1)

Sernst
Sernst

Reputation: 524

Lambda functions requires a handler in the format <FILE-NAME-NO-EXTENSION>.<FUNCTION-NAME>. In your case the handler is set to lambda_function.lambda_handler, which is the default value assigned by AWS Lambda). However, you've named your file hello_python.py. Therefore, AWS Lambda is looking for a python file named lambda_function.py and finding nothing.

To fix this either:

  1. Rename your hello_python.py file to lambda_function.py
  2. Modify your lambda function handler to be hello_python.lambda_handler

You can see an example of how this works in the documentation where they create a python function called my_handler() inside the file hello_python.py, and they create a lambda function to call it with the handler hello_python.my_handler.

Upvotes: 9

Related Questions