npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

knex-aurora-data-api-mysql

v3.0.2

Published

Knex.js driver for MySQL AWS Aurora Data API

Downloads

121

Readme

knex.js driver for MySQL AWS Aurora Data API

Tired of dealing with the challenges of managing MySQL servers?

  • Scaling up or down requires manual intervention or complex autoscaling policies and can require downtime
  • Managing a pool of connections is tedious and can exhaust server resources with idle connections
  • Development database instances are wasted when developers aren't actively using them
  • Patching with minor and patch versions is time consuming and tedious
  • Credentials must be stored in a confidential and encrypted location and retrieved at runtime
  • Primary and replicas must be maintained for high-availability utilizing complex DNS resolution failover
  • File system utilization must be monitored and disk space added when needed

AWS Aurora Serverless to the rescue!

Aurora Serverless abstracts away the challenges of maintaining MySQL database servers. The service scales database clusters up and down (including all the way to 0) depending on connection load. Minor and patch versions are applied automatically without downtime. Fault-tolerant, multi-region clusters are provisioned for you, with automated storage management built-in.

Further, the AWS Aurora Data API makes it easy to perform queries on Aurora Serverless clusters using HTTP connections and standard AWS IAM temporary credentials. The Data API allows for connection multiplexing across processes making it easier to operate at lower, cheaper scale than request pooling may require.

This Node.js module provides a driver for knex.js to utilize the AWS Aurora Data API to achieve these benefits using standard Knex.js semantics.

Usage

First, create an Aurora Serverless Database. Make sure you can execute queries against it as shown in the AWS docs.

Next install the module:

$ npm install --save knex knex-aurora-data-api-mysql

Then simply provide this module as the client, supply the database name, and specify the AWS resource identifiers and credentials to connect to your Aurora Serverless cluster:

const knex = require('knex')({
  client: require('knex-aurora-data-api-mysql'),
  connection: {
    database: '<Database Name>', // e.g. 'project'
    resourceArn: '<Aurora Serverless Cluster ARN>', // e.g. 'arn:aws:rds:us-west-2:012345678901:cluster:mydbcluster'
    secretArn: '<AWS Secrets Manager Credentials ARN>', // e.g. 'arn:aws:secretsmanager:us-west-2:012345678901:secret:rds-db-credentials/mydbcluster/user',
    
    // Optional AWS SDK configuration if not available through process environment variables like AWS_PROFILE and AWS_REGION
    sdkConfig: {
      region: '<AWS Region>',
      accessKeyId: '<AWS Access Key ID>',
      secretAccessKey: '<AWS Secret Access Key>'
    }
  }
});

console.log(await knex('accounts').columnInfo());

Limitations

  • While transactions are supported, nested transactions are not. The AWS Aurora Data API does not support savepoints. This means you can't do something like:
let id = 231;
let name = 'Barb';
let role = 'Admin';

knex.transaction(async trx => {
  trx('users').update({ name }).where({ id });
  trx('roles').update({ role }).where({ id });

  try {
    // Creating a nested transaction will always fail
    await trx.transaction(async trx2 => {
      await trx2('events').insert({ event: 'User Update', id });
    });
  } catch (err) {
    console.log(`Tried to insert event for updating user ${id} but failed: ${err}`;
  }
});

Breaking Changes

Version 2 to 3

Version 3 uses version 3 of the AWS SDK. This SDK is included automatically in the nodejs18.x AWS Lambda runtime and above.

@aws-sdk/client-rds-data and @smithy/node-http-handler are only included as dev dependencies. You will need to make sure those two packages are available in some form in your project.

Version 1 to 2

Version 1 depended on aws-sdk, which at the time of the change was 71 MB in size. This package may be used in contexts where package size is important and the SDK may already be available, such as AWS Lambda Functions.

Version 2 drops aws-sdk from a dependency to a dev dependency. This means you need to make sure the aws-sdk package is available in some form in your project. This can be accomplished by adding aws-sdk to your project's dependencies, or by allowing the package to be implicitly provided like it is in AWS Lambda Functions.