AWS Lambda package deployment

别来无恙 提交于 2019-12-12 19:35:46

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/35782388/aws-lambda-package-deployment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!