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
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,
EC2 and lambda in us-west region
JDBC Code:
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);