Connecting EC2 to RDS Using Playback Mode

I have a small site that I created using the Play platform, which I am trying to run on an EC2 server against an Amazon RDS instance. I can run the application on my machine against an RDS instance, and everything works fine. But when I deploy it on 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.javahaps81)
         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 that it was some kind of security setting, but I have a Spring based application running on Tomcat on the same EC2 server connecting to the same RDS instance with the same username and password, and it It works just fine, only the Play application has connection problems.

It seems I can’t explain why this is happening, or ideas on how to fix it.

Has anyone seen anything like this before?

+7
java amazon-ec2 amazon-rds playframework
source share
4 answers

The problem is with the application.conf file. If you specify a local database as follows:

db=mysql:root:pass@db 

and your prod DB as follows:

 %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 you try to start in the production process, because Play! actually trying to use db = mysql: root: pass @db param to connect, since prod parameters do not override this parameter sepecifically. To fix this, be sure to connect to the database locally in prod as well. 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 
+2
source share

I don’t know anything about one of these frameworks (or Java in general), but I have some experience working with both of these Amazon services - is it possible that these frameworks exchange data using different protocols or in different ports? If so, it is still a security issue.

If possible, go to EC2> Security Groups, and if you do not have these three lines, try adding them:

 All | icmp | -1 | -1 | default group All | tcp | 0 | 65535 | default group All | udp | 0 | 65535 | default group 

("default group" is the default name, and what I called mine, but your group name may be different - in any case, make sure that this is the name of the group, not "0.0.0.0/0")

In addition, if you know specific protocols / ports, you need to open them and then add them too.

0
source share

Your error can be caused by any number of things and seems to happen at a lower level of the protocol stack than what you are looking at. I recommend running a packet analyzer (such as wireshark ) on the sending server to try to figure out what is happening. Maybe packages don't get there? Maybe your client is confusing something because of what environment he is in? A packet sniffer can be invaluable for unraveling the mysteries of dysconnection.

If your server is silent or you cannot redirect the graphical session, you can always use a command line tool such as tcpdump on * nix systems.

0
source share

I asked the same question here

Connectivity with Amazon RDS and Elastic Beanstalk

Most likely, your problem will be fixed after you add to the default security group the default RDS group, the "elastic item-default" security group.

0
source share

All Articles