Search code examples
node.jsamazon-web-servicesvpnamazon-vpcsnowflake-cloud-data-platform

Snowflake nodejs driver returns Unable to connect: Network error. Could not reach Snowflake


I'm using snowflake through VPN connection and need to setup snowflake on nodejs project. I followed these steps mentioned in https://docs.snowflake.com/en/user-guide/nodejs-driver-use.html# doc.

  1. nodejs version v12.18.0
  2. installed snowflake-sdk (version 1.6.1)
const snowflake = require('snowflake-sdk');
snowflake.configure({ ocspFailOpen: false });

const snowflakeDatabase = {
    accessUrl:
        'https://xyz.region.privatelink.snowflakecomputing.com:7756',
    account: 'xyz.region.privatelink',
    authenticator: 'SNOWFLAKE',
    username: 'my_user_name',
    password: 'my_password',
    insecureConnect: true,
    clientSessionKeepAlive: true,
    jsTreatIntegerAsBigInt: true,
};

connection = snowflake.createConnection(snowflakeDatabase);

createPool = () => {
    if (!connection) {
        connection = snowflake.createConnection(snowflakeDatabase);
    }

    if (!connection.isUp()) {
        connection.connect(function (err, conn) {
            if (err) {
                console.error('Unable to connect: ' + err.message);
            } else {
                console.log('Successfully connected to Snowflake.');
                // Optional: store the connection ID.
                connection_ID = conn.getId();
            }
        });
        console.log('connection status:', connection.isUp());
    }

    return connection;
};

closePool = () => {
    connection.destroy(function (err, conn) {
        if (err) {
            console.error('Unable to disconnect: ' + err.message);
        } else {
            console.log(
                'Disconnected connection with id: ' + connection.getId()
            );
        }
    });
};

module.exports = {
    createPool: createPool,
    closePool: closePool,
};

but it returns following response

(node:10188) UnhandledPromiseRejectionWarning: OperationFailedError: IP {{IP_ADDRESS}} is not allowed to access Snowflake.  Contact your local security administrator.
    at createError (myfolder\node_modules\snowflake-sdk\lib\errors.js:529:15)
    at Object.exports.createOperationFailedError (myfolder\node_modules\snowflake-sdk\lib\errors.js:308:10)
    at Object.callback (myfolder\node_modules\snowflake-sdk\lib\services\sf.js:624:28)
    at Request.<anonymous> (myfolder\node_modules\snowflake-sdk\lib\http\base.js:107:19)
    at Request._callback (myfolder\node_modules\lodash\lodash.js:10118:25)
    at Request.requestRetryReply [as reply] (myfolder\node_modules\requestretry\index.js:115:19)
    at Request.<anonymous> (myfolder\node_modules\requestretry\index.js:156:10)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:10188) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:10188) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Here I used VPN connection and I'm already have .pem file to the my organization VPC. I used following ssh command to create ssh tunnel.

ssh -L 7756:xyz.region.privatelink.snowflakecomputing.com:443 -l user_name -N server_name -p port_number -i my_file.pem

Please help to resolve this


Solution

  • It seems your IP is blocked or not allowed in the network policy in Snowflake. Can you reach out to users having AccountAdmin/SecurityAdmin privilege to allow your IP in Snowflake?

    Ref: https://docs.snowflake.com/en/user-guide/network-policies.html