Amazon web services 如何从aws lambda连接专用RDS
我正在进行JDBC连接,以便从Lambda函数访问AWS RDS,RDS可访问性是私有的,它允许访问我的EC2公共IP,因此我可以在EC2实例中连接,但当我的Lambda函数每5分钟调用一次时,它给出以下错误Amazon web services 如何从aws lambda连接专用RDS,amazon-web-services,amazon-ec2,aws-lambda,amazon-rds,mssql-jdbc,Amazon Web Services,Amazon Ec2,Aws Lambda,Amazon Rds,Mssql Jdbc,我正在进行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 milliseco
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.
美国东部地区,
美国西部地区的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);
您需要在VPC内部部署Lambda,因为您的RDS不公开。您是否在这些区域之间启用了VPC对等?你有合适的安全组吗?是的,我有ec2安全组,我在其中添加了mysql端口3306的规则。对等怎么样?您添加到安全组的规则是什么?你提供的信息越多,你得到答案的可能性就越高。我没有使用窥视,我对窥视了解不多,我已经在我的EC2安全组中为3306授予了anywhere访问权限@KDG如果您在RDS安全组中只白列EC2公共IP,并且两个AWS区域之间没有VPC对等,EC2实例可以连接到RDS实例,则RDS实例必须配置为可公开访问。因此,您问题中的一条信息肯定是不正确的。我在默认VPC中部署了lambda,但仍然收到相同的错误,我想知道我应该在默认VPC中更新什么以连接专用rds?