I have a Laravel web app set up on Elastic Beanstalk and it can connect to the RDS database just fine. I have the environment variables set up through the configuration setting in EB. When I ssh into the EC2 instance and run a custom artisan command that queries the database like "sudo php artisan check-companies", I get the error SQLSTATE[HY000] [2002] Connection refused (SQL: the query)". What could be causing this error? Here are a few things to note and what I've tried.
- I have workers that run the same artisan command every day and it works.
- I'm able to connect to the Aurora Cluster from MYSQL command line utility and run queries when I ssh into the instance.
- I've tried exposing the environment variables to the instance as shown here: https://aws.amazon.com/premiumsupport/knowledge-center/elastic-beanstalk-env-variables-shell/
- I made sure port 3306 is open in my security group