对此有多个问题/答案,但没有一个解决方案似乎有效。
我目前的设置是:
我正在使用psycopg2进行连接,这是在我的requirements.txt
文件中。我尝试了一个简单的SELECT查询,如下所示:
conn = psycopg2.connect(dbname=os.environ['DB_NAME'], user=os.environ['USERNAME'], password=os.environ['PASSWORD'])
cursor = conn.cursor()
query = "SELECT * from {};".format(os.environ['TABLE'])
cursor.execute(query)
records = cursor.fetchall()
这给了我错误:
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
: OperationalError
Traceback (most recent call last):
File "/var/task/mylambda.py", line 31, in call
conn = psycopg2.connect(dbname=os.environ['DB_NAME'],
user=os.environ['USERNAME'], password=os.environ['PASSWORD'])
File "/tmp/sls-py-req/psycopg2/__init__.py", line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
我错过了什么?如何从Lambda成功连接到RDS? 谢谢!