我正在建立JDBC连接以从Lambda函数访问AWS RDS,RDS可访问性是私有的,它允许访问我的EC2公共IP,因此我能够在EC2实例中进行连接,但是当我的lambda函数每5个调用一次时分钟,其出现以下错误
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
美国东部地区的RDS,
美国西部地区的EC2和lambda
JDBC代码:
String username = prop.getProperty("dbUser");
String password = prop.getProperty("dbPassword");
String driver = prop.getProperty("dbDriver");
String url = prop.getProperty("dbUrl"); // RDS endpoint
String jdbcUrl = url + "?user=" + username + "&password=" + password;
logger.info("Creating JDBC MySQL Connection "+driver);
Class.forName(driver);
connection = DriverManager.getConnection(jdbcUrl);
答案 0 :(得分:0)
由于RDS不公开,因此您需要在VPC中部署Lambda。