Amazon RDS and Elastic Beanstalk connectivity

2019-05-15 22:50发布

There are already several threads where this question is discussed, and I have already tried implementing suggestions discussed in Elastic Beanstalk -> RDS connection error using Grails.

  • I have also opened ports to accept connections from "All" for ICMP, TCP and UDP in my EC2 instance.

  • I have made sure that my RDS and EC2 instances are in the same zone (Eastern)

  • I have also added the "elasticbeanstalk-default" security group in RDS default security group

  • I have added my local machine's IP address in RDS CIDR settings, and I am able to connect to RDS through SQLYog from my machine.

BUT when I try to connect my RDS instance from Elastic Beanstalk I am getting the following exception

Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:310)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:176)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:163)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:384)
at java.net.Socket.connect(Socket.java:546)
at java.net.Socket.connect(Socket.java:495)
at java.net.Socket.<init>(Socket.java:392)
at java.net.Socket.<init>(Socket.java:235)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:256)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:293)
... 18 more

Jun 1, 2011 5:12:41 AM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
Jun 1, 2011 5:12:41 AM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [] startup failed due to previous errors
Jun 1, 2011 5:12:41 AM org.apache.catalina.core.StandardContext listenerStop
SEVERE: Exception sending context destroyed event to listener instance of class         org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener
 org.springframework.beans.factory.BeanCreationException: Error creating bean with name.....
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:636)

My DataSource.groovy parameters are as follows.

production {
    dataSource {
        pooled = true
        dbCreate = "update" // one of 'create', 'create-drop','update'
        url = "jdbc:mysql://[MyEndPoint]:3306/*****"
        username = "*****"
        password = "*****"
        dialect = org.hibernate.dialect.MySQL5InnoDBDialect
        properties {
            validationQuery = "SELECT 1"
            testOnBorrow = true
            testOnReturn = true
            testWhileIdle = true
            timeBetweenEvictionRunsMillis = 1000 * 60 * 30
            numTestsPerEvictionRun = 3
            minEvictableIdleTimeMillis = 1000 * 60 * 30
        }
    }
}

1条回答
贼婆χ
2楼-- · 2019-05-15 23:29

I solved it, pretty foolish answer though.

I always felt (thought) that when building a new WAR file for a Grails project in NetBeans it is created in a "production" environment, but that was not the case. I had to go to the project properties and change "Active grails environment" setting to "production" and this fixed it.

In a nutshell Amazon Web Services Elastic Beanstalk was trying to connect to my development environment database "localhost".

查看更多
登录 后发表回答