AWS Lambda RDS 连接超时 [英] AWS Lambda RDS connection timeout

查看:36
本文介绍了AWS Lambda RDS 连接超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用连接到我的 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.

我经过一番研究得出的结论是,这可能是一个安全问题,但在亚马逊的文档或 this 答案(这是我在该主题上唯一能找到的答案).

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).

这里是安全细节:

  • 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 由于某种原因不起作用,即使它位于亚马逊的默认示例中.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆