0
votes

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);
1
Do you have VPC peering enabled between these regions? Do you have an appropriate security group? - kdgregory
yes I have ec2 security group where i have added rule for mysql port 3306 - Naveen kumawat
How about peering? And what exactly is the rule that you added to the security group? The more information that you provide, the higher the likelihood that you'll get an answer. - kdgregory
I am not using peering and i don't know much about peering, i have given anywhere access permission to 3306 in my EC2 security group. @kdgregory - Naveen kumawat
If you only white-listed the EC2 public IP in the RDS security group, and you don't have VPC peering between the two AWS regions, and the EC2 instance can connect to the RDS instance, then the RDS instance must be configured to be publicly accessible. So one of the pieces of information in your question must be incorrect. - Mark B

1 Answers

0
votes

You need to deploy your Lambda inside VPC as your RDS is not publicly available.