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

aws-sigv4-auth-cassandra-plugin

v1.0.5

Published

A sigv4 authentication plugin for open-source Datastax NodeJS Driver for Apache Cassandra

Downloads

2,979

Readme

IMPORTANT: Latest Version

The current version is 1.0.5. Please see the changelog for details on version history.

What

This package implements an authentication plugin for the open-source Datastax NodeJS Driver for Apache Cassandra. The driver enables you to add authentication information to your API requests using the AWS Signature Version 4 Process (SigV4). Using the plugin, you can provide users and applications short-term credentials to access Amazon Keyspaces (for Apache Cassandra) using AWS Identity and Access Management (IAM) users and roles.

The plugin depends on the AWS SDK for NodeJS. It uses AWSCredentialsProvider to obtain credentials. You must specify the service endpoint to use for the connection. You can provide the Region in the constructor programmatically, via the AWS_REGION environment variable.

The full documentation for the plugin is available at Amazon Keyspaces AWS Docs.

Using the Plugin

The following sections describe how to use the authentication plugin for the open-source DataStax NodeJS Driver for Cassandra to access Amazon Keyspaces.

SSL Configuration

The first step is to get an Amazon digital certificate to encrypt your connections using Transport Layer Security (TLS). The DataStax NodeJS driver must use an SSL trust store so that the client SSL engine can validate the Amazon Keyspaces certificate on connection. To use the trust store and create a certificate, see Using a Cassandra Java Client Driver to Access Amazon Keyspaces Programmatically.

Region Configuration

Before you can start using the plugin, you must configure the AWS Region that the plugin will use when authenticating. This is required because SigV4 signatures are Region-specific. For example, if you are connecting to the cassandra.us-east-2.amazonaws.com endpoint, the Region must be us-east-2. For a list of available AWS Regions and endpoints, see Service Endpoints for Amazon Keyspaces.

You can specify the Region using one of the following four methods:

  • Environment Variable
  • System Property
  • Constructor
  • Configuration

Environment Variable

You can use the AWS_REGION environment variable to match the endpoint that you are communicating with by setting it as part of your application start-up, as follows.

$ export AWS_Region=us-east-1

Add the Authentication Plugin to the Application

The authentication plugin supports version 4.x of the DataStax NodeJS Driver for Cassandra. To add this application use

$ npm install aws-sigv4-auth-cassandra-plugin --save

How to use the Authentication Plugin

When using the open-source DataStax NodeJS driver, the connection to your Amazon Keyspaces endpoint is represented by the Client class.

Programmatically Configure the Driver

When using the DataStax NodeJS driver, you interact with Amazon Keyspaces primarily through the Client class.

To use the authentication plugin, you set a Region-specific instance of SigV4AuthProvider as the authentication provider, as in the following example.

  1. Create a SigV4AuthProvider from plugin.
  2. Add an SSL context using AmazonRootCA1.pem ssl and Keyspaces endpoint.
  3. Set the local data center to the region name, in this example it is us-west-2. The local data center is used by the driver for routing of requests, and it is required when the builder is constructed with addContactPoints.
  4. Set the authentication provider to a new instance of the SigV4AuthProvider. You can specify the Region for the endpoints that you’re using in the constructor for SigV4AuthProvider, as in the following example. Or, you can set the environment variable or system property as shown previously.

The following code example demonstrates the previous steps.

const cassandra = require('cassandra-driver');
const fs = require('fs');
const sigV4 = require('aws-sigv4-auth-cassandra-plugin');

const auth = new sigV4.SigV4AuthProvider({
    region: 'us-west-2', 
    accessKeyId:'AKIAIOSFODNN7EXAMPLE',
    secretAccessKey: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY'});

const sslOptions1 = {
  ca: [
      fs.readFileSync('~/.cassandra/AmazonRootCA1.pem', 'utf-8')],
  host: 'cassandra.us-west-2.amazonaws.com',
  rejectUnauthorized: true
};


const client = new cassandra.Client({
  contactPoints: ['cassandra.us-west-2.amazonaws.com'],
  localDataCenter: 'us-west-2',
  authProvider: auth,
  sslOptions: sslOptions1,
  protocolOptions: { port: 9142 }
});


const query = 'SELECT * FROM system_schema.keyspaces';

client.execute(query).then(
    result => console.log('Row from Keyspaces %s', result.rows[0]))
    .catch( e=> console.log(`${e}`));