AWS Lambda 函数返回相同的值,除非重新部署

AWS Lambda function returning same values unless redeployed

我有一个连接到 mysql rds 的简单 AWS Lambda 函数。当我在我的应用程序 UI 中更新一个字段时,它会在从 MySQL workbench 查看时在数据库中更新它,但是在使用 Lambda 函数时它 returns 相同的值,直到我重新部署函数然后它给了我新的正确值

"""Search Function for Lambda""" 

from urllib.parse import unquote
import json
import pymysql

# Configuration Values
##CONFIG VALUES REMOVED


# Connection
connection = pymysql.connect(ENDPOINT, user=USERNAME,
                             passwd=PASSWORD, db=DATABASE_NAME)


def get(event, context):
    """Takes searches key from event and searches the database on that key"""
    print(context)
    cursor = connection.cursor()
    search_key = unquote(event['pathParameters']['search_key'])
    cmd = ('SELECT * from LCI_Data WHERE Description Like "{}"'.format("%"+search_key+"%"))
    cursor.execute(cmd)
    result = [dict((cursor.description[i][0], value)
              for i, value in enumerate(row)) for row in cursor.fetchall()]

    response = {
                "statusCode": 200,
                "body": json.dumps(result),
                "headers": {
                    "Access-Control-Allow-Origin": "*",
                    "Access-Control-Allow-Credentials": "true"
                }
            }
    return response

移动

connection = pymysql.connect(ENDPOINT, user=USERNAME,
                             passwd=PASSWORD, db=DATABASE_NAME) 

进入 get() 函数解决了我的问题。