1

I am trying to connect to one of my Redshift clusters so that I can fetch data from one of the tables there. I am using Node.js for it.

I used the createCluster() method and created a cluster, but I cannot seem to find a method to read from/connect to it. The aws docs are rather confusing for me as I am new to the aws environment.

How can I connect to an existing cluster and get some data out of a table in it?

Thanks :)

Rohit
  • 1,385
  • 2
  • 15
  • 21

7 Answers7

4

npm i node-redshift

you can connect using this npm name node-redshift https://www.npmjs.com/package/node-redshift

OR

regarding the AWS, i think this will help you

Trying to Connect to Redshift Over AWS Lambda

Narendra Chouhan
  • 2,291
  • 1
  • 15
  • 24
  • I tried using the node-redshift module but it is giving me the "getaddrinfo ENOTFOUND" error. Could you tell me what's causing this? – Rohit Apr 02 '19 at 07:28
  • also, what should I mention in place of 'host'? is it the cluster endpoint? – Rohit Apr 02 '19 at 07:29
  • i tried with the cluster endpoint. the 'getaddrinfo ENOTFOUND' error is gone, but i don't get any result. it shows timed out after some seconds! – Rohit Apr 03 '19 at 05:29
  • 1
    that means you are requesting for connection and server is not respondig for your connect so that why its showing you the timed out after few seconds , leave a commit below – Narendra Chouhan Apr 03 '19 at 05:33
  • could you go through [this](https://jsfiddle.net/bunnyrabbit/57u4Lcxb/1/) code and tell me what's wrong? The `redshiftClient.connect()` is not getting called. – Rohit Apr 03 '19 at 05:48
  • @RohitMishra yes i will go through your code, but if you error is been solved and only the connect part is giving you the time out than it code structure mistake , i will have a look and i will help you , but can you mark the answer as correct and pls up vote the answer so that if can other come here they can get the solutions too – Narendra Chouhan Apr 03 '19 at 05:54
  • i am providing you the example that will help you to understand http://www.digitalbrix.com/blog/?p=86 OR https://github.com/dmanjunath/node-redshift/blob/master/examples/connection_pooling.js, – Narendra Chouhan Apr 03 '19 at 06:13
  • thanks bro, but i already saw those articles. do u see any error in my code? – Rohit Apr 03 '19 at 06:24
  • @RohitMishra i have provide the link in the above commit pls check it and thanks for the vote up , if you feel that link help you, you can mark it as correct answer – Narendra Chouhan Apr 03 '19 at 06:24
  • you should remove the connect code as specifiy in link – Narendra Chouhan Apr 03 '19 at 06:26
3

I was trying to make the 'node-redshift' module work before I asked this question here. I found out what I was missing out on. I had to have a security group associated with my cluster. There was no option to create a security group in my region (Asia Pacific - Mumbai). I changed the region and was able to create the group, set the appropriate port and IP and it worked.

Rohit
  • 1,385
  • 2
  • 15
  • 21
2

To those who are using node-redshift, it was working fine with 12.13.1 but was not responding for 14.15.0 LTS.

Maybe you may want to check your Node version once.

Vijender R
  • 29
  • 1
1

I was able to connect AWS-Lambda to Redshift importing 'node-redshift' module into the Lambda Function. The most important thing while creating lambda layer try to make the layer for 'node-redshift' package for version nodejs10.x. I tried adding the layer for nodejs14.x and was struggling to make a connection to Redshift which was not happening. So after changing the version from nodejs14.x to nodejs10.x it worked. Moreover thanks to Vijender R, his answer also gave me the direction to change the versioning for working with the 'node-redshift' package.

maxkashyap
  • 11
  • 2
0

Had the same issue, the reason - I've updated node.js. After returned it to version 11.1.0, everything works ok.

The solution is to find something instead node-redshift (since it was updated 4 years ago)

user1067939
  • 93
  • 1
  • 1
  • 6
0

It may be worth trying to use https://www.npmjs.com/package/@aws-sdk/client-redshift-data, which seems to be maintained by AWS itself.

Leo
  • 1,160
  • 18
  • 31
0

I tried making node-redshift work for a long time ... eventually found an alternative solution using pg-promise - https://javaniceday.com/how-to-connect-to-a-redshift-database-from-node-js/

I had to add '?ssl=true' to the connection string in that example, but then my strapi project was finally able to pull in redshift data.

Kory
  • 96
  • 2