2016-03-03 207 views
0

我試圖部署一個Python的.zip包作爲一個AWS LambdaAWS Lambda包部署

我選擇hello-python Footprint。

我使用內聯代碼創建了第一個lambda表達式,之後我嘗試更改爲從開發.zip上傳。

我使用的包是一個.zip包含具有相同的代碼作爲默認內聯代碼樣品,這在下面示出稱爲hello_python.py單個文件:

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') 

後我點擊「保存和測試」,什麼都沒有發生,但我得到這個奇怪的紅絲帶,但沒有其他實質性的錯誤信息。如果修改來源,重新打包並再次上傳,則日誌和運行結果不會有任何變化。 enter image description here

+0

CloudWatch Logs中是否顯示任何內容? – James

回答

6

Lambda函數需要格式爲<FILE-NAME-NO-EXTENSION>.<FUNCTION-NAME>的處理程序。在你的情況下,處理程序設置爲lambda_function.lambda_handler,這是AWS Lambda分配的默認值)。但是,您已將您的文件命名爲hello_python.py。因此,AWS Lambda正在尋找一個名爲lambda_function.py的python文件,但沒有發現任何內容。

爲了解決這個問題之一:

  1. 重命名hello_python.py文件lambda_function.py
  2. 修改您的lambda函數處理程序是hello_python.lambda_handler

你可以看到這是如何工作的documentation爲例他們在文件hello_python.py內創建了一個名爲my_handler()的python函數,並且它們創建了一個lambda函數來用處理函數調用它hello_python.my_handler