【发布时间】:2021-03-17 12:16:36
【问题描述】:
我正在尝试使用以下 lambda 函数连接到 AWS 上的 msql 数据库
const dotenv = require('dotenv');
dotenv.config();
var mysql = require('mysql');
var pool = mysql.createPool({
host : process.env.DBHOST,
user : process.env.DBUSER,
password : process.env.DBPASSWORD,
database : process.env.DBNAME
});
exports.handler = (event, context, callback) => {
//prevent timeout from waiting event loop
context.callbackWaitsForEmptyEventLoop = false;
pool.getConnection(function(err, connection) {
// Use the connection
connection.query('select * from products', function (error, results, fields) {
// And done with the connection.
connection.release();
// Handle error after the release.
if (error) callback(error);
else callback(null,results[0].emp_name);
});
});
};
执行时出现以下错误:
Response:
{
"errorMessage": "2020-12-05T16:51:55.273Z 281776f1-ee7f-4c8c-8862-a7371d1a8f37 Task timed out after 3.00 seconds"
}
请求 ID: "281776f1-ee7f-4c8c-8862-a7371d1a8f37"
功能日志:
START RequestId: 281776f1-ee7f-4c8c-8862-a7371d1a8f37 Version: $LATEST
END RequestId: 281776f1-ee7f-4c8c-8862-a7371d1a8f37
REPORT RequestId: 281776f1-ee7f-4c8c-8862-a7371d1a8f37 Duration: 3003.58 ms Billed Duration: 3000 ms Memory Size: 128 MB Max Memory Used: 75 MB Init Duration: 202.41 ms
2020-12-05T16:51:55.273Z 281776f1-ee7f-4c8c-8862-a7371d1a8f37 Task timed out after 3.00 seconds
我该如何解决这个问题?
【问题讨论】:
-
您是否将 Lambda 函数部署到与 RDS 实例相同的 VPC 中?您使用的是 AWS RDS 代理还是 RDS Aurora Serverless?
-
"任务在 3.00 秒后超时" - 将默认超时时间从 3 秒增加到更多,假设它可以访问 vpc。
标签: mysql amazon-web-services amazon-rds amazon-vpc