AWS Lambda RDS连接超时 [英] AWS Lambda RDS connection timeout
问题描述
我试图使用连接到我的RDS数据库的Node.js编写Lambda函数.该数据库正在运行,并且可以从我的Elastic Beanstalk环境访问.当我运行该函数时,它将返回超时错误.
I'm trying to write a Lambda function using Node.js which connects to my RDS database. The database is working and accessible from my Elastic Beanstalk environment. When I run the function, it returns a timeout error.
试图将超时延长到5分钟,结果完全相同.
Tried to increase the timeout up to 5 minutes with the exact same result.
经过一些研究,我得出的结论是,这可能是一个安全问题,但无法在Amazon文档或
The conclusion I came to after some research is that it's probably a security issue but couldn't find the solution in Amazon's documentation or in this answer (which is the only one I could find on the topic).
以下是安全性详细信息:
Here are the security details:
- RDS和Lambda都在同一个安全组中.
- RDS具有所有流量的入站和出站规则.
- Lambda的角色具有AmazonVPCFullAccess策略.
我的代码是:
'use strict';
console.log("Loading getContacts function");
var AWS = require('aws-sdk');
var mysql = require('mysql');
exports.handler = (event, context, callback) => {
var connection = mysql.createConnection({
host : '...',
user : '...',
password : '...',
port : 3306,
database: 'ebdb',
debug : false
});
connection.connect(function(err) {
if (err) callback(null, 'error ' +err);
else callback(null, 'Success');
});
};
我得到的结果是:
"errorMessage": "2017-03-05T05:57:46.851Z 9ae64c49-0168-11e7-b49a-a1e77ae6f56c Task timed out after 10.00 seconds"
推荐答案
我要感谢所有帮助过的人,但事实证明这个问题与我想像的有所不同.代码中的callback
由于某种原因而无法使用,即使它位于AMAZON的默认样本中也是如此.
I want to thank everyone who helped, the problem turned out to be different than I thought. The callback
in the code doesn't work for some reason even though it's in AMAZON'S OWN DEFAULT SAMPLE.
工作代码如下:
'use strict';
console.log("Loading getContacts function");
var AWS = require('aws-sdk');
var mysql = require('mysql');
exports.handler = (event, context) => {
var connection = mysql.createConnection({
host : '...',
user : '...',
password : '...',
port : 3306,
database: 'ebdb',
debug : false
});
connection.connect(function(err) {
if (err) context.fail();
else context.succeed('Success');
});
};
这篇关于AWS Lambda RDS连接超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!