2016-03-28 4 views
0

私は、handlerというハンドラでPythonで新しいラムダ関数を作成しました。 「設定」セクションでは、AWSで関数の名前をfile-name.function-nameという形式で記述する必要があります(説明はhere)。ラムダ関数のファイル名の検索方法は?

しかし、私はファイル名が何であると考えているのか分かりません。私は空の関数を作成したが、ファイル名を指定しなかった。私の関数名は "MySQLTest"なので、 "MySQLTest.handler"、 "my-sql-test.handler"、 "mysqltest.handler"のようなさまざまなものを試しましたが、どれも動作していないようです。

私はファイル名として何を置くべきでしょうか?詳細については

、これは私が使用しているテストコードです:

import sys 
import logging 
import rds_config 
import pymysql 
#rds settings 
rds_host = "*******" 
# "rds-instance-endpoint" 
name = rds_config.db_username 
password = rds_config.db_password 
db_name = rds_config.db_name 
port = 3306 

logger = logging.getLogger() 
logger.setLevel(logging.INFO) 

server_address = (rds_host, port) 
try: 
    conn = pymysql.connect(rds_host, user=name, passwd=password, db=db_name, connect_timeout=5) 
except: 
    logger.error("ERROR: Unexpected error: Could not connect to MySql instance.") 
    sys.exit() 

logger.info("SUCCESS: Connection to RDS mysql instance succeeded") 
def handler(event, context): 
    """ 
    This function fetches content from mysql RDS instance 
    """ 

    item_count = 0 

    try: 
     with conn.cursor() as cur: 
      cur.execute("create table Employee3 (EmpID int NOT NULL, Name varchar(255) NOT NULL, PRIMARY KEY (EmpID))") 
      cur.execute('insert into Employee3 (EmpID, Name) values(1, "Joe")') 
      cur.execute('insert into Employee3 (EmpID, Name) values(2, "Bob")') 
      cur.execute('insert into Employee3 (EmpID, Name) values(3, "Mary")') 
      cur.execute("select * from Employee3") 
      for row in cur: 
       item_count += 1 
       logger.info(row) 
       #print(row) 
    finally: 
     conn.close() 

    return "Added %d items from RDS MySQL table" %(item_count) 
+0

あなたはAWSコンソールを介して、この機能を追加しましたか? – garnaat

+0

@ garnaat、右、AWSコンソールで –

答えて

1

あなたがAWSコンソール経由で機能を追加する場合は、ユーザーが指定する名前は<name of lambda function>.handlerでなければなりません(あなたがPythonの関数handlerと呼ばれると仮定。だから、

、私のラムダ関数の名前がfooBarで、私のPythonの関数がhandler呼び出された場合、私はfooBar.handlerを使用します。