Aiven services are managed from the Aiven web console. First, log in to the console with your email address and password, and you will be automatically taken to the "Services" view that shows all of the services under the currently selected project.

Projects allows you to organize groups of services under different topics and each project can even have different billing settings. An empty project is automatically created for you upon sign up and the free credits are attached to this project. 

You can create new projects by clicking the project dropdown at the top of the sidebar and selecting "Create a new project". The same menu can also be used to switch between projects.

To get started with Cassandra, first click the "Create a new service" button.

The dialog that opens allows you to specify the main service properties:

  • Service name: A short name for the service used to distinguish it from others. A random name is provided, but you can type in a more user-friendly one.
  • Service type: Select "Cassandra".
  • Plan: How many servers and what kind of memory/CPU/disk resources will be allocated to run your service.
  • Cloud: Which cloud and region to run the service on. Note: the pricing of the same service may differ between cloud providers and their regions.

After selecting your service properties, click the "Create" button and you will be taken back to the service list view displaying the newly selected service with an indicator that it is being created.

Click the service name in the list and the service's "Overview" information page will open. Aside from displaying the service's connection parameters and its status, this view is where you can make changes to the service.

The "Status" indicator will say "REBUILDING" while the service is being created for you. Once the service is up and running, the light will change to green and it will say "RUNNING". Note: while services typically start in minutes, the performance between clouds varies and it can take longer in some cases.

The Cassandra cluster is initiated with a superuser role named avnadmin. The role can be used to create keyspaces and additional roles with any tool or library supporting the Cassandra protocol.

Data center and replication

Your Cassandra cluster is created with all nodes in a Data Center (DC) named aiven. It's recommended to use the NetworkTopologyStrategy replication strategy when creating keyspaces to ensure replicas of your data are distributed on nodes in different Availability Zones (AZ) within the service's selected cloud. 

While SimpleStrategy has a replication factor property, it may place the replicas in the same AZ. The examples below demonstrate how to create keyspaces with NetworkTopologyStrategy using the aiven DC.

Cqlsh example

The CQL shell is an easy way to try out your new Cassandra service. Since connections to Aiven are always encrypted and cqlsh needs a certificate file to validate the server, click on the Show CA certificate button and download the certificate. 

Point the SSL_CERTIFICATE environment variable to the downloaded file and run cqlsh with command-line parameters for username, password, hostname and port copied from the Connection parameters section of the Cassandra service view:

$ SSL_CERTFILE=ca.pem cqlsh --ssl -u avnadmin -p cevt9db1v7vxgrxu cassandra-1e39e4d8-myfirstcloudhub.aivencloud.com 20985
Connected to 7ad8a118-d885-4077-9db4-95dbc53cd258 at cassandra-1e39e4d8-myfirstcloudhub.aivencloud.com:26882.
[cqlsh 5.0.1 | Cassandra 3.11.1 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
avnadmin@cqlsh> CREATE KEYSPACE example_keyspace WITH REPLICATION = {'class': 'NetworkTopologyStrategy', 'aiven': 3};
avnadmin@cqlsh> USE example_keyspace;
avnadmin@cqlsh:example_keyspace> CREATE TABLE example_table (id int PRIMARY KEY, message text);
avnadmin@cqlsh:example_keyspace> INSERT INTO example_table (id, message) VALUES (123, 'Hello world!');
avnadmin@cqlsh:example_keyspace> SELECT id, message FROM example_table;

 id  | message
-----+--------------
 123 | Hello world!

(1 rows)

Python example

This example uses the cassandra-driver library to connect as the avnadmin role to create a keyspace with a table, and then insert a row into the table and select it. It assumes the CA certificate file has been saved into a file named ca.pem in the working directory:

import ssl
from cassandra.cluster import Cluster
from cassandra.auth import PlainTextAuthProvider

host = "cassandra-1e39e4d8-myfirstcloudhub.aivencloud.com"
port = 20985
auth_provider = PlainTextAuthProvider("avnadmin", "cevt9db1v7vxgrxu")
ssl_options = {"ca_certs": "ca.pem", "cert_reqs": ssl.CERT_REQUIRED}

with Cluster([host], port=port, ssl_options=ssl_options, auth_provider=auth_provider) as cluster:
    with cluster.connect() as session:
        session.execute("CREATE KEYSPACE example_keyspace WITH REPLICATION = {'class': 'NetworkTopologyStrategy', 'aiven': 3}")
        session.execute("USE example_keyspace")
        session.execute("CREATE TABLE example_table (id int PRIMARY KEY, message text)")
        session.execute("INSERT INTO example_table (id, message) VALUES (%s, %s)", (123, "Hello world!"))
        for row in session.execute("SELECT id, message FROM example_table"):
            print("Row: id = {}, message = {}".format(row.id, row.message))

Java example

This example uses the Java version of cassandra-driver. It also assumes the CA certificate has been saved into ca.pem:

package io.aiven.help;

import com.datastax.driver.core.*;

import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManagerFactory;
import java.io.FileInputStream;
import java.security.KeyStore;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;

public class Example {
    private static SSLOptions loadCaCert() throws Exception {
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        FileInputStream fis = null;
        X509Certificate caCert;
        try {
            fis = new FileInputStream("ca.pem");
            caCert = (X509Certificate) cf.generateCertificate(fis);
        } finally {
            if (fis != null) {
                fis.close();
            }
        }

        TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
        ks.load(null);
        ks.setCertificateEntry("caCert", caCert);
        tmf.init(ks);

        SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(null, tmf.getTrustManagers(), null);
        return RemoteEndpointAwareJdkSSLOptions.builder().withSSLContext(sslContext).build();
    }

    public static void main(String[] args) throws Exception {
        String host = "cassandra-1e39e4d8-myfirstcloudhub.aivencloud.com";
        int port = 20985;
        String username = "avnadmin";
        String password = "cevt9db1v7vxgrxu";

        SSLOptions sslOptions = loadCaCert();

        Cluster cluster = null;
        try {
            cluster = Cluster.builder()
                    .addContactPoint(host)
                    .withPort(port)
                    .withSSL(sslOptions)
                    .withAuthProvider(new PlainTextAuthProvider(username, password))
                    .build();
            Session session = cluster.connect();
            session.execute(
                    "CREATE KEYSPACE example_keyspace WITH REPLICATION = {'class': 'NetworkTopologyStrategy', 'aiven': 3}"
            );
            session.execute("USE example_keyspace");
            session.execute("CREATE TABLE example_table (id int PRIMARY KEY, message text)");
            session.execute("INSERT INTO example_table (id, message) VALUES (?, ?)", 123, "Hello world!");
            ResultSet rs = session.execute("SELECT id, message FROM example_table");
            for (Row row : rs) {
                System.out.println(String.format("Row: id = %d, message = %s", row.getInt("id"), row.getString("message")));
            }
        } finally {
            if (cluster != null) {
                cluster.close();
            }
        }
    }
}

Did this answer your question?