简体   繁体   中英

Execute queries on Amazon Redshift using the AWS SDK for JavaScript

I have been following aws-sdk for javascript to execute sql queries on redshift cluster but haven't been able to connect.

Can someone guide me regarding module to use for redshift connection in javascript (except node-redshift) or share a skeleton code with proper parameter names?

Using @aws-sdk/client-redshift

 const RedShiftClient = new RedshiftClient({region:'us-west-2'}); const params = { ClusterIdentified:'clustername-xxx-aws.com', NodeType: 'nodetype', MasterUsername:'user', MasterPassword:'password', ClusterType:'clustertype' }; const command = new AcceptReservedNodeExchangeCommand(params); redshiftClient.send(command) .then(res=>{ //dosomething }) .catch(err=>{ console.log(err); });

Receiving error : 2 validation errors found: Value null at 'targeReservedNodeOfferingId' failed to satisfy constraint. Member cannot be null. Value null at 'reserverNodeId' failed to satify constraint. Member cannot be null.

To execute queries on Amazon Redshift using JavaScript, use RedshiftDataClient (not RedShiftClient ). There are examples in the previous link. This is part of the AWS SDK for JavaScript v3 .

To use a RedshiftDataClient object to query data, you can use the following Amazon Redshift values:

  • The name of the database (for example, dev)
  • The name of the database user that you configured
  • The name of the Amazon Redshift cluster (for example, redshift-cluster-1)

These values are used when creating an ExecuteStatementCommand as discussed here:

https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-redshift-data/classes/executestatementcommand.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM