I have a small site I built using the Play framework that I'm trying to run on an EC2 server against an Amazon RDS instance. I can run the app on my machine against the RDS instance and everything works fine. But when I deploy it to my EC2 server it gets this error:
The last packet successfully received from the server was 1,282,977,731,085 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago. at play.db.DBPlugin.onApplicationStart(DBPlugin.java:87) at play.Play.start(Play.java:381) at play.Play.init(Play.java:247) at play.server.Server.main(Server.java:85) Caused by: java.net.ConnectException: Connection refused
My first thought was it was some kind of security setting, but I have a Spring based application running in Tomcat on the same EC2 server connecting to the same RDS instance with the same username and password, and it works just fine. Only the Play app has connection issues.
I can't seem to come up with any explanation for why this is happening, or ideas on how to fix it.
Anyone seen anything like this before?
You need to ssh to the machine using instance's credentials like username password or key file. Then, once connected to ec2 instance, you can use db endpoint credentials to connect to RDS instance using SQL connection commands.
The problem is with the application.conf file. If you specify your local DB like this:
db=mysql:root:pass@db
and your prod DB like this:
%prod.db.url=jdbc:mysql://<your-db-ip>:3306/db
%prod.db.user=db_user
%prod.db.pass=db_pass
You will get this error when trying to run in production because Play! is actually trying to use the db=mysql:root:pass@db param to connect since the prod params don't override that parameter sepecifically. To fix this, be sure to connect to the DB in the same way locally and in prod. This worked for me:
db.url=jdbc:mysql://localhost:3306/db
db.user=root
db.pass=pass
%prod.db.url=jdbc:mysql://<your-db-ip>:3306/db
%prod.db.user=db_user
%prod.db.pass=db_pass
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With