错误:连接ETIMEDOUT RDS Lambda [英] Error: connect ETIMEDOUT rds lambda

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

问题描述

我正在尝试使用Lambda函数连接到RDS,但出现错误:

I am trying to connect to RDS using Lambda function, but I am getting an error:

var mysql = require('mysql');
exports.handler = function(event, context) {   
           //Connect to RDS

var connection = mysql.createConnection({
host     : 'hostname',
user     : 'username',
password : 'password',
database : 'database'

});

connection.connect( function(err)
{
   if (err)
   { 
     throw err;
   }
else 
  {
    console.log('DB connection establish');
  }
  });

 };

我得到的错误是:

START RequestId: 9711e650-e582-11e5-af5f-97ba391a42ae Version: $LATEST

2016-03-08T23:08:06.737Z    9711e650-e582-11e5-af5f-97ba391a42ae    
Error: connect ETIMEDOUT  
  at Connection._handleConnectTimeout (/var/task/node_modules/mysql/lib/Connection.js:412:13)       
      at Socket.g (events.js:180:16)   
    at Socket.emit (events.js:92:17)   
    at Socket._onTimeout (net.js:327:8)     
    at _makeTimerTimeout (timers.js:429:11)   
    at Timer.unrefTimeout [as ontimeout] (timers.js:493:5)    
    --------------------
    at Protocol._enqueue (/var/task/node_modules/mysql/lib/protocol   /Protocol.js:141:48)    
    at Protocol.handshake (/var/task/node_modules/mysql/lib/protocol    /Protocol.js:52:41)      
    at Connection.connect (/var/task/node_modules/mysql     /lib/Connection.js:123:18)     
    at exports.handler (/var/task/exports.js:21:12)     
END RequestId: 9711e650-e582-11e5-af5f-97ba391a42ae        
REPORT RequestId: 9711e650-e582-11e5-af5f-97ba391a42ae  
Duration: 10988.17ms    
Process exited before completing request

推荐答案

我遇到了同样的问题,并且已经解决. 鉴于这是Stackoverflow上该问题的最高搜索结果,因此我将在此处发布我的解决方案.

I had the same problem as this and just got it fixed. Seeing as this is the top search result for this problem on stackoverflow, I am going to post my solution here.

此答案适用于VPC内的RDS实例

This answer is for an RDS instance inside a VPC

  1. 将Lambda函数与RDS实例放置在同一VPC中
  2. 您的lambda执行角色,您将需要具有VPC执行策略 AWSLambdaVPCAccessExecutionRole

  1. place the Lambda function in the same VPC as your RDS instance
  2. your lambda execution role you will need to have VPC execution policy AWSLambdaVPCAccessExecutionRole

将安全组分配给lambda函数

assign a security group to the lambda function

总而言之,这会将lambda与RDS放在同一VPC中,并且使lambda函数可以入站访问MYSQL,而不管lambda函数的IP是什么.

In summary this places the lambda in the same VPC as RDS and gives the lambda function inbound access to MYSQL regardless of the IP of the lambda function.

这篇关于错误:连接ETIMEDOUT RDS Lambda的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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