简体   繁体   English

如何找到lambda函数的文件名?

[英]How to find filename of lambda function?

I've created a new lambda function in Python with a handler called handler . 我已经在Python中使用名为handler的处理handler创建了一个新的lambda函数。 In the Configuration section, AWS requires me to put the name of the function in the form file-name.function-name (as described here ). 在配置部分,AWS要求我的形式把函数的名称file-name.function-name (如描述在这里 )。

However I have no idea what the filename is supposed to be. 但是我不知道文件名应该是什么。 I've created a blank function and didn't specify a filename at any point. 我创建了一个空白函数,并且在任何时候都没有指定文件名。 My function name is "MySQLTest" so I've tried various things like "MySQLTest.handler", "my-sql-test.handler", "mysqltest.handler" but none of it seems to work. 我的函数名称是“ MySQLTest”,所以我尝试了诸如“ MySQLTest.handler”,“ my-sql-test.handler”,“ mysqltest.handler”之类的各种方法,但它们似乎都不起作用。

Any idea what I should put as a filename? 知道我应该把什么作为文件名吗?

For info, this is the test code I'm using: 有关信息,这是我正在使用的测试代码:

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)

If you are adding the function via the AWS Console the name you supply should be <name of lambda function>.handler (assuming you called your Python function handler . 如果要通过AWS控制台添加函数,则提供的名称应为<name of lambda function>.handler (假设您称为Python函数handler

So, if the name of my Lambda function is fooBar and my Python function is called handler I would use fooBar.handler . 因此,如果我的Lambda函数的名称为fooBar而我的Python函数称为handler ,则应使用fooBar.handler

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM