[英]How to connect private RDS from aws lambda
I am making JDBC connection to access AWS RDS from Lambda function, RDS accessibility is private, which allows to access to my EC2 public IP, so i am able to connect in EC2 instance but when my lambda function is calling in every 5 minutes, its giving following error我正在建立 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 in us-east region,美国东部地区的RDS,
EC2 and lambda in us-west region美国西部地区的 EC2 和 lambda
JDBC Code: 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);
您需要在 VPC 内部署您的 Lambda,因为您的 RDS 不是公开可用的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.