Rohit
Rohit

Reputation: 1523

How can I connect to my redshift cluster using Node.js?

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 :)

Upvotes: 2

Views: 11962

Answers (7)

Kory
Kory

Reputation: 96

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.

Upvotes: 0

Leo
Leo

Reputation: 1240

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.

Upvotes: 0

user1067939
user1067939

Reputation: 93

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)

Upvotes: 0

maxkashyap
maxkashyap

Reputation: 11

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.

Upvotes: 1

Vijender R
Vijender R

Reputation: 29

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.

Upvotes: 2

Rohit
Rohit

Reputation: 1523

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.

Upvotes: 3

Narendra Chouhan
Narendra Chouhan

Reputation: 2319

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

Upvotes: 4

Related Questions