0
votes

I am new to AWS, may you please help me.

Was following this tutorial: enter tutorial link

Created a RDS and ran this code below in visual studio code:

File name:test.js

var mysql = require('mysql');
var config = require('./config.json');
var pool  = mysql.createPool({
    host     : config.dbhost,
    user     : config.dbuser,
    password : config.dbpassword,
    database : config.dbname
  });
pool.getConnection(function(err, connection) {
  // Use the connection
  connection.query('SELECT emp_name from Employee where emp_id=1', function (error, results, fields) {
    // And done with the connection.
    connection.release();
    // Handle error after the release.
    if (err) throw error;
    else console.log(results[0].emp_name);
    process.exit();
  });
});

However, when i run node test.js , it returned the following error.

(base) zi-jies-mbp:sql zijie$ node test.js /Users/zijie/node_modules/mysql/lib/protocol/Parser.js:437 throw err; // Rethrow non-MySQL errors ^

TypeError: Cannot read property 'query' of undefined at /Users/zijie/Documents/I&E/Silverride/sql/test.js:11:14 at Handshake.onConnect (/Users/zijie/node_modules/mysql/lib/Pool.js:58:9) at Handshake. (/Users/zijie/node_modules/mysql/lib/Connection.js:525:10) at Handshake._callback (/Users/zijie/node_modules/mysql/lib/Connection.js:491:16) at Handshake.Sequence.end (/Users/zijie/node_modules/mysql/lib/protocol/sequences/Sequence.js:83:24) at Handshake.ErrorPacket (/Users/zijie/node_modules/mysql/lib/protocol/sequences/Handshake.js:125:8) at Protocol._parsePacket (/Users/zijie/node_modules/mysql/lib/protocol/Protocol.js:291:23) at Parser._parsePacket (/Users/zijie/node_modules/mysql/lib/protocol/Parser.js:433:10) at Parser.write (/Users/zijie/node_modules/mysql/lib/protocol/Parser.js:43:10) at Protocol.write (/Users/zijie/node_modules/mysql/lib/protocol/Protocol.js:38:16)

May you please share and advice me on what is the error about, and how to remedy it? Thanks in Advance.

1

1 Answers

1
votes

As per your error

TypeError: Cannot read property 'query' of undefined at

It seems that the connection object is not created. This can be due to combination of things such as

  • you are not passing the correct parameters for the connection
  • RDS security group is not allowing the connection (It seems to be an issue faced by multiple people using that tutorial: check comments)