简体   繁体   English

AWS Lambda上的节点功能无法使用node-pg连接到数据库

[英]Node function on AWS Lambda can't connect to database with node-pg

My function works locally, but, when I deploy to AWS Lambda, it can't seem to connect to my postgres database. 我的函数在本地工作,但是当我部署到AWS Lambda时,它似乎无法连接到我的postgres数据库。 Here's the error: 这是错误:

{ [Error: connect ECONNREFUSED] code: 'ECONNREFUSED', errno: 'ECONNREFUSED', syscall: 'connect' }, isOperational: true, code: 'ECONNREFUSED', errno: 'ECONNREFUSED', syscall: 'connect' }

My database is hosted on an Azure virtual machine, and I'm not having problems connecting to it from any other app nor from this app when run locally. 我的数据库托管在Azure虚拟机上,在本地运行时,从任何其他应用程序或从此应用程序连接到数据库都没有问题。 What could be causing the connection to fail when running on Lambda? 在Lambda上运行时,可能导致连接失败的原因是什么?

It turned out to be something dumb. 原来是愚蠢的东西。 I am using node-lambda and thought the .env file it creates was propagated to the function's environment. 我正在使用node-lambda,并认为它创建的.env文件已传播到函数的环境。 Logging my DB connection string showed this wasn't the case. 记录我的数据库连接字符串表明情况并非如此。 Once I set that, everything was golden. 一旦设置好,一切就变得很黄金。

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

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