Elastic Beanstalk app won't connect to RDS MySQL instance

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

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.


Did you launch the RDS instance into VPC as well?

Your RDS security group needs to grant incoming traffic on port 3306 to the beanstalk security group.

e.g RDS security group

Incoming
ALLOW TCP 3306 from BeanstalkSG

Don't open to 0.0.0.0

Since you already allow all traffic outgoing, your Beanstalk SG does not have to grant 3306 for outgoing traffic additionally.

Do your VPC ACLs allow traffic on 3306? (They do, by default)