1
votes

I have an ElasticBeanstalk application that uses Docker to run a small Laravel PHP API.

The app cannot connect to MySQL when running in ElasticBeanstalk.

The MySQL DB is a publically available AWS RDS instance.

I've run my Docker container locally and the app can connect just fine.

When I deploy to ElasticBeanstalk the app cannot connect...

Can anyone point me in a direction to help debug this?

SOLUTION

For anyone else who stumbles on this:

The solution was to create a new security group for both the EC2 instances and the RDS database. The two security groups opened up access via port 3306 for the instances and the database.

I also ensured the EC2 instances were available across every subnet and in the same VPC as my database.

Taken from the answers below and bit of help from a SysOps friend of mine.

2
security group rules says: "By default, security groups allow all outbound traffic"...I have the same problem, why wouldn't it let me connect?Alexander Mills
here is a relevant link that should be in the OP: docs.aws.amazon.com/AWSEC2/latest/UserGuide/…Alexander Mills
Hi @AlexanderMills this was last year, so my memory is foggy, however, I think "security groups allow all outbound traffic" is true. You need to allow inbound traffic on 3306 on both your EC2 instance and your RDS DB. And both should be in the same VPC... and available on the same subnet. Does that help you?MattDavies
@MattDavies How do you setup the the database address for docker in this case? Please share how you defined the db address environment variable.dryleaf

2 Answers

1
votes

High chance that your ec2 instance does not have a public ip assigned to it. If you're trying to connect to the public IP of RDS without a public ip on the ec2 instance you won't be able to.

The ec2 instance will either need a public ip or it will need to have external internet connectivity through NAT.

1
votes

You may want to check the EC2 Security Group Rules attached to Elastic Beanstalk to allow TCP at port 3306 for MYSQL type.