Skip to content
Advertisement

Cannot connect to database stored on aws from Heroku or Replit websites. (mysql2, node.js)

Problem: My discord.js bot isn’t connecting to the mysql database on aws. The bot is being hosted on replit and also on heroku but for some reason I can’t connect to both. I have tried connecting to the database from my laptop and it worked fine, I even hosted the bot on my laptop to see if there was a problem with the code but it connected just fine, it even wrote data on the database.

edit: the pw and host are written like that because this is from replit and I stored those values on .env so no one would see it.

Error: (node 475) UnhandledPromiseRejectionWarning: Error: ETIMEDOUT at PromisePool.query

Here is the code I’m using:

async function connect(){
const mysql = require('mysql2/promise');


    const pool = mysql.createPool({
        host: process.env['host'],
        user: 'admin',
        password: process.env['chave'],
        database: 'prdcorridas_main',
        port: 3306,
        waitForConnections: true,
        connectionLimit: 20,
        queueLimit: 0

    },);

    return pool;
}
connect()

async function query(query){
    const conn = await connect();
    return await conn.query(query);
}

module.exports = {query}

Advertisement

Answer

I found the problem, it was just a human error probably due to my tiredness when creating the database.

Solution: I had forgotten to specify to the aws website the ip address of the machine hosting the bot because I purposely restricted the ‘income access’ to the ip addresses listed only.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement