Connect to a External DB (RDS AMAZON)


#1

I’m having issues trying to connect to my DB in Aurora Cluster (AWS), I migrate my project from adonis 3.2 to 4.1 in 3.2 the conexion was fine so I don’t understand why is not working now.

My .env File looks like

DB_CONNECTION=mysql
DB_HOST=aurora-cluster.cluster.us-east-1.rds.amazonaws.com
DB_PORT=3306
DB_USER=[MY_USER]
DB_PASSWORD=[MY PASSWORD]
DB_DATABASE=[MY DB NAME]

note the DB_HOST is not the real path, sorry but I cant share that info only the id is missing.

That structure was working fine on 3.2 .

This is the error
{ Error: ER_ACCESS_DENIED_ERROR: Access denied for user ‘Simple’@’[THIS IS THE IP OF MY SERVER NOT THE CLUSTER URL]’ (using password: YES)
at Handshake.Sequence._packetToError (/Users/simpledev/Development/[APP_DIRECTORY]/node_modules/mysql/lib/protocol/sequences/Sequence.js:52:14)

THe credentials are fine I’m 100% sure of that

Can you helpme please!!!


#2

I have fought with connecting to aws rds before and there were some security groups I had to setup to allow adonis connect (both from my local for debugging and from my ec2 instance), so I would double check that.

Additionally check your database config under [projectRoot]/config/database.js

there should be a section there:

mysql: {
client: 'mysql',
connection: {
  host: Env.get('DB_HOST', 'localhost'),
  port: Env.get('DB_PORT', '3306'),
  user: Env.get('DB_USER', "someuser"),
  password: Env.get('DB_PASSWORD', 'somepass'),
  database: Env.get('DB_DATABASE', 'somedb')
},
debug: Env.get('DB_DEBUG', false)
},

Hope that helps :slight_smile:


#3

THANKS FOR ANSWERING

I will double check the database.js but i think its fine, its weird because when i switch to adonis 3.2 the conextion to my DB is working.


#4

Yup NP!

Now I am hardly an expert with adonis (mostly trial and error during creating an api) but one thing that helps me and could help here is try to create a minimum reproducible error.

In this case I would try to create a new 4.1 adonis project with no real business logic and a new local mysql instance (I use docker) and try to connect with that, then after success try the aws connection and debug from there.

Thats my two cents.


#5

Can you connect to the database server from your machine using command line?


#6

Yes.

If I run the mysql command i can connect to my DB.

The issue is when I try to use Lucid or run the migrations. Something is different in adonis 4.1 because it was working on 3.2, and I dont know what it is. Even if I try to use the IP of my aurora cluster instead of the url I get the Access denied error.


#7

SOLVED!!!
I fixed the Issue, Everything was right.

Something was happening with my password from the driver (database.js) to the actual mysql connection.For example: my DB_PASSWORD on my .env was ‘$ample999!’ but when I check the values before the connection my password was “!”, so what I did is remove the special characters from my password and it worked!.

To check the values before the connection I opened the file
Adonis 4.1:

node_modules/knex/lib/dialects/mysql/index.js

line 101 method “acquireRawConnection” add this code “console.log(_this.connectionSettings)”

you will see the values on your terminal.

Thanks for your Help!!!