skip to Main Content

I am trying to connect to an RDS instance via my Macbook (M1, Sonoma 14.2.1), and am constantly running into this error. Initially I thought the error was that my instance was not publicly accessible, which I have now changed.

Error message here:

Unable to connect to the database: HostNotFoundError [SequelizeHostNotFoundError]: getaddrinfo ENOTFOUND your_amazon_rds_host
at Client._connectionCallback (/Users/as/Desktop/sample_app/node_modules/sequelize/lib/dialects/postgres/connection-manager.js:134:24)
at Client._handleErrorWhileConnecting (/Users/as/Desktop/sample_app/node_modules/pg/lib/client.js:327:19)
at Client._handleErrorEvent (/Users/as/Desktop/sample_app/node_modules/pg/lib/client.js:337:19)
at Connection.emit (node:events:519:28)
at Socket.reportStreamError (/Users/as/Desktop/sample_app/node_modules/pg/lib/connection.js:58:12)
at Socket.emit (node:events:519:28)
at emitErrorNT (node:internal/streams/destroy:169:8)
at emitErrorCloseNT (node:internal/streams/destroy:128:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
    parent: Error: getaddrinfo ENOTFOUND your_amazon_rds_host
    at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:118:26) {
        errno: -3008,
        code: 'ENOTFOUND',
        syscall: 'getaddrinfo',
        hostname: 'your_amazon_rds_host'
    },
    original: Error: getaddrinfo ENOTFOUND your_amazon_rds_host
    at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:118:26) {
        errno: -3008,
        code: 'ENOTFOUND',
        syscall: 'getaddrinfo',
        hostname: 'your_amazon_rds_host'
    }
}

For what it’s worth, here are some relevant details I have included in my .env file:

AWS RDS Instance:
Endpoint: database-1.servername.us-east-1.rds.amazonaws.com
Username: postgres
Password: RandomPassword
DB Instance Identifier: database-1
Database Port: 5432

Security Group Inbound Rules

Type: All traffic
Protocol: All
Port Range: All

What am I missing?

2

Answers


  1. please check all these think

    The error message you are encountering (getaddrinfo ENOTFOUND your_amazon_rds_host)

    Check the RDS Instance Status

    Correct Hostname or IP Address

    Security Group and Firewall Settings

    Login or Signup to reply.
  2. Since you can resolve the DNS name but are still unable to connect, focus on the Sequelize configuration and network settings.

    The fact that you can resolve the DNS name of your RDS instance to an IP address is a good sign. It means that your MacBook is correctly resolving the RDS endpoint. However, the ping failure could be due to AWS security settings, as AWS often blocks ICMP (ping) traffic.

    Make sure your Sequelize setup in the Node.js application is using the correct hostname. Replace 'your_amazon_rds_host' with the actual endpoint of your RDS instance.

    Your Sequelize updated configuration would be:

    const Sequelize = require('sequelize');
    
    // Replace these values with the actual details from your .env file
    const sequelize = new Sequelize('databaseName', 'username', 'password', {
      host: 'database-1.servername.us-east-1.rds.amazonaws.com', // Correct host
      dialect: 'postgres',
      port: 5432
    });
    
    sequelize.authenticate()
      .then(() => {
        console.log('Connection has been established successfully.');
      })
      .catch(err => {
        console.error('Unable to connect to the database:', err);
      });
    

    Try also to use a different PostgreSQL client (like pgAdmin or DBeaver) to test the connection with the same credentials. That can help determine if the issue is with Sequelize or the network.
    Double-check that the security group attached to your RDS instance allows inbound traffic on port 5432 from your IP address. Also, make sure any Network Access Control Lists (NACLs) are not blocking this traffic.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search