Using cqlsh to connect to Amazon Keyspaces - Amazon Keyspaces (for Apache Cassandra)

Using cqlsh to connect to Amazon Keyspaces

The following section describes how to use cqlsh to connect to Amazon Keyspaces (for Apache Cassandra).

For information about cqlsh, see cqlsh: the CQL shell.

Installing and using cqlsh to connect to Amazon Keyspaces (for Apache Cassandra)

To install and use cqlsh, you must do the following:


To make cqlsh connections to Amazon Keyspaces for functional testing, light operations, and migrations you can use a preconfigured Docker container that includes all prerequisites and configuration settings optimized for Amazon Keyspaces. The toolkit is available on the GitHub website.

Install Python 2.7

To determine whether you have Python installed on your computer and which version, run the following operation.

python --version

If you have Python 2.7 installed, you should see something like the following for output.

Python 2.7.16

If you need to install Python 2.7, follow the instructions at Python downloads.

Install and configure the CQL client

cqlsh is bundled with Apache Cassandra. To get it, install Apache Cassandra by following the instructions in Downloading and installing Apache Cassandra. Amazon Keyspaces supports drivers and clients that are compatible with Apache Cassandra 3.11.2. The currently recommended version of cqlsh can be downloaded from Apache.

After installing Cassandra, verify that cqlsh is installed by running the following command.

cqlsh --version

You should see something like the following for output.

cqlsh 5.0.1

If you are using Windows, replace all instances of cqlsh with cqlsh.bat. For example, to check the version of cqlsh in Windows, run the following command.

cqlsh.bat --version

Download the template of the configuration file cqlshrc optimized for Amazon Keyspaces from Github. Save the downloaded cqlshrc_template file as cqlshrc to the Cassandra directory.


Encrypting cqlsh connections using TLS

Amazon Keyspaces only accepts secure connections using Transport Layer Security (TLS).

Before you can connect using SSL/TLS, you must do the following:

  1. Download the Starfield digital certificate using the following command and save sf-class2-root.crt locally or in your home directory.

    curl -O

    You can also use the Amazon digital certificate to connect to Amazon Keyspaces and can continue to do so if your client is connecting to Amazon Keyspaces successfully. The Starfield certificate provides additional backwards compatibility for clients using older certificate authorities.

  2. Connect to Amazon Keyspaces with the following command.


    The ServiceUserName and ServicePassword should match the ones obtained when you generated the service-specific credentials by following the steps in Generate service-specific credentials.

    You can also manage Amazon Keyspaces cqlsh access through AWS IAM users and roles by using the AWS authentication plugin expansion for cqlsh. To learn more, see Amazon Keyspaces (for Apache Cassandra) developer toolkit on Github.

    cqlsh host 9142 -u ServiceUserName -p ServicePassword --ssl

    Note that 9142 is the secure port.

    The following is an example.

    cqlsh 9142 -u "alice-at-111122223333" -p "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" --ssl

    After connecting, you see something like the following for output. The currently supported version of Apache Cassandra is 3.11.2.

    Connected to Amazon Keyspaces at [cqlsh 5.0.1 | Cassandra 3.11.2 | CQL spec 3.4.4 | Native protocol v4] Use HELP for help. alice-at-111122223333@cqlsh>

Updating an existing configuration file for cqlsh connections

If you want to edit an existing configuration file to support TLS connections, open the configuration file in the Cassandra home directory, for example ${HOME}/.cassandra/cqlshrc and add the following lines.

[connection] port = 9142 factory = cqlshlib.ssl.ssl_transport_factory [ssl] validate = true certfile = path_to_file/sf-class2-root.crt

You can configure cqlsh COPY settings to ensure cqlsh stays within the Amazon Keyspaces CQL query throughput tuning guidelines.

Modify the default for the COPY FROM option in the configuration file ${HOME}/.cassandra/cqlshrc and add the following lines.

[copy-from] CHUNKSIZE=50

This setting for CHUNKSIZE works well to get started with a newly created table and should be changed to support larger workloads. For more information on how to optimize cqlsh COPY configuration settings for Amazon Keyspaces, see Step 4: Configure cqlsh COPY FROM settings in the data migration tutorial.