Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elastic Beanstalk app won't connect to RDS MySQL instance

Tags:

I have a CodeIgniter PHP app setup on an Elastic Beanstalk instance. I'm trying to connect it to a RDS MySQL instance I setup but loading the Elastic Beanstalk site URL always results in the page timing out the connection. I've narrowed down the issue to not being able to connect to the database.

I think I've setup my security groups properly to allow the Elastic Beanstalk EC2 instances to talk to RDS, but something must be wrong as the page still doesn't load.

I've included screenshots below of the inbound/outbound rules for the security group that RDS and Elastic Beanstalk use, as well as a screenshot of what security groups I have attached to the Elastic Beanstalk instance.

Inbound rules

Outbound rules

enter image description here

Any ideas as to why my Elastic Beanstalk app can't talk to my RDS instance?


EDIT: The RDS instance and the Elastic Beanstalk instance are in the same security group.

like image 505
Tim Jahn Avatar asked Oct 18 '15 05:10

Tim Jahn


People also ask

Does Elastic Beanstalk use RDS?

You can use Elastic Beanstalk with Amazon Relational Database Service (Amazon RDS) to set up, operate, and scale a relational database. There are two options to get started, which are the following. Create a new database in Amazon RDS.

What are some of the common causes why you Cannot connect to a DB instance on AWS?

When you can't connect to a DB instance, the following are common causes: Inbound rules – The access rules enforced by your local firewall and the IP addresses authorized to access your DB instance might not match. The problem is most likely the inbound rules in your security group.


2 Answers

Add the stack security group name you have your Elastic Beanstalk set up with to the list of RDS security groups.

It is easiest to test by logging into the EC2-instance (i.e. eb ssh) and test the connection to the database to exclude any issues with your app.

mysql -u user -p password -h rds.instance.endpoint.region.rds.amazonaws.com
like image 192
Gustaf Avatar answered Sep 28 '22 04:09

Gustaf


There is now a tutorial on how to connect ElasticBeanstalk with any RDS database (MySQL etc), in a way that does not bind the two together, i.e. you can create them separately. The tutorial goes into setting up security groups via the AWS console.

After that, you have to set 5 ElasticBeanstalk environment variables (at least for MySQL): RDS_HOSTNAME, RDS_PORT, RDS_DB_NAME, RDS_USERNAME & RDS_PASSWORD.

Different ElasticBeanstalk instances would access these variables in different ways to make a database connection (I know in PHP, you have to use $_SERVER['RDS_DB_NAME'], etc). See how to do it in Java, Node.js, Python, Ruby, and .NET in in the link above.

like image 22
Abhishek Divekar Avatar answered Sep 28 '22 04:09

Abhishek Divekar