jeremydaly / data-api-client

A "DocumentClient" for the Amazon Aurora Serverless Data API
MIT License
439 stars 61 forks source link

Disabling ssl only works if keep alive is also disabled #33

Closed jackstevenson closed 4 years ago

jackstevenson commented 4 years ago

sslEnabled: false for local dev fails with the following error 'Protocol "http:" not supported. Expected "https:"'. To work around this issue you must also disable keepAlive to prevent the custom httpsAgent being configured

const dataClient = require('data-api-client')({
  resourceArn: '*******',
  secretArn: '*******',
  database: '*******',
  sslEnabled: false,
  keepAlive: false, // <------- work around
  options: {
    endpoint: 'localhost:8080',
  },
});
jackstevenson commented 4 years ago

Looking into this a little further it's possible to enable connection keep-alive by setting an environment variable. From the docs:

The easiest way to configure SDK for JavaScript to reuse TCP connections is to set the AWS_NODEJS_CONNECTION_REUSE_ENABLED environment variable to 1.

It might be preferable to use this built-in config and defer to the SDK for agent configuration rather than having a keepAlive option in this lib. If that's not the case you would need to configure an http.Agent and conditionally set the httpOptions based on the sslEnabled option - essentially duplicating what the SDK already does.

In addition to this, the sslEnabled and region options could be removed as it's possible to pass these in to the RDSDataService using the already available options param.

Example config:

const dataClient = require('data-api-client')({
  resourceArn: '*******',
  secretArn: '*******',
  database: '*******',
  options: {
    endpoint: 'localhost:8080',
    sslEnabled: false,
    region: 'eu-west-1',
  },
});