If you did not attend the previous weeks' workshop STOP - Complete Week 2 - Data Modelling first.
Welcome to the 'App Dev of back end with Cassandra' workshop! In this two-hour workshop, the Developer Advocate team of DataStax presents the process and the basic tenets of backend App Dev. If you did not attend the previous workshops, please look at the previous weeks of the bootcamp Week 1 - Intro to Cassandra and Week 2 - Data Modelling.
For the hands-on part of this workshop, we will use Astra DB, a Database-as-a-Service built on Cassandra and delivered by DataStax.
It doesn't matter if you join our workshop live or you prefer to do at your own pace, we have you covered. But please if you did not attend Week 1 - Intro to Cassandra and/or Week 2 - Data Modelling we suggest you get caught up since the material in this workshop will build on top of the previous weeks' workshops!
In this repository, you'll find everything you need for this workshop:
- Materials used during presentations
- Hands-on exercises
- Workshop video
- Discord chat
- Questions and Answers
To complete the workshop and get a verified badge, follow these simple steps:
- Watch the workshop live or recorded. Pick a language and run through the exercises.
- Write a new exercise/test: Transfer/Copy all Todoitems from any one user_id to a new user_id with completed being false. At the very least one Todoitem should be created.
- Submit the Homework through this form and attach the screenshots above.
- Give us a few days to review your submission and relax: your well-earned badge will soon land in your mailbox!
Title | Description |
---|---|
Slide deck | Slide deck for the workshop |
1. Connect to your Astra DB instance | Connect to your Astra DB instance |
2. Create Astra Token | Create Astra Token |
3. Launch Gitpod | Launch Gitpod |
4. Know your Gitpod | Know your Gitpod |
5. Setup your Application | Setup for the Applications |
6-6f. CRUD with Cassandra | CRUD with Cassandra |
7. Badges | Badges |
Once again, If you did not attend the previous workshops, please look at the previous weeks of the bootcamp Week 1 - Intro to Cassandra and Week 2 - Data Modelling please complete that first.
✨ Please visit https://astra.datastax.com to create your free Astra DB instance, required for today's hands-on exercises! 🔥 More details here on how to proceed.
Verify that the keyspace todos
indeed exists in database workshops
as shown in the Astra dashboard.
Now that you've created a database and keyspace already and familiarized yourself with the Astra console, we will start preparing to connect to the database, programmatically.
There are several language drivers (includes Java, NodeJS, Python) to access a Cassandra database programmatically and each with different capabilites. The driver matrix is at https://docs.datastax.com/en/driver-matrix/doc/driver_matrix/common/driverMatrix.html.
In principle, they all work by setting up a connection to the database and manipulating the data via CQL statements or higher abstractions referred to as collections.
We will start by establishing connectivity (which is common across languages) and then branch off into the respective language paths.
To establish connectivity to the Astra database that we created, we need some credentials from the Astra console and we need to use a secure connect bundle alongside the driver. The next few steps will accomplish just that.
We need to create a token that we will use as our credentials.
✅ Step 2a: Generate Token
Following the Manage Application Tokens docs create a token with Database Administrator
roles.
-
Go the
Organization Settings
-
Go to
Token Management
-
Pick the role
Database Admnistrator
on the select box -
Click Generate token
👁️ Walkthrough
This is what the token page looks like. You can now download the values as a CSV since you will need those values very soon.
Notice the clipboard icon at the end of each value.
-
Client Id:
We will use it as a username to connect to Astra. -
Client Secret:
We will use it as a password to connect to Astra. -
appToken:
It can be used as an api token Key to interact with APIs. (we won't be using this in today's workshop)
To know more about roles, tokens, etc. you can look at this video.
Note: Make sure you don't close the window accidentally or otherwise - if you close this window before you copy the values, the application token is lost forever. They won't be available later for security reasons. You'll have to create a new application token
⚠️ ImportantThe instructor will show you on screen how to create a token but will have to destroy to token immediately for security reasons.
We are now set with the database and credentials. Let's start coding!
Gitpod is an IDE 100% online based on VS Code. To initialize your environment simply click on the button below (CTRL + Click to open in new tab) You will be asked for your github account, as needed.
👁️ Expected output
The screenshot may be slightly different based on your default skin and a few edits in the read me.
That's it. Gitpod provides all tools we will need today including for respective languages.
You may safely ignore the error output at the end of the terminal window.
👁️ Expected output
Although GitPod terminal might seem to be available, the setup might still be ongoing. Wait for a few minutes before entering commands in the GitPod terminal window.
You are not going to run any command in this step but it's a great idea to take a moment and familiarize yourself with Gitpod. These steps provides some details for just that. Take a tour around and get comfortable.
Take a moment to read this entire section since it'll help you with the rest of the workshop as you'll be spending most of your time in Gitpod. If you're familiar with Gitpod, you can easily skip this entire section.
The extreme left side has the explorer view(1). The top left, middle to right is where you'll be editing files(2), etc. and the bottom left, middle to right is what we will refer to as the Gitpod terminal window(3) as shown below.
👁️ Expected output
You can always get back to the file explorer view whenever by clicking on the hamburger menu on the top left followed by View
and Explorer
as shown below.
At the top right of the terminal window is a +
sign which allows you to create multiple shells. Familiarize yourself since we will be using cql
in one of the shells.
You may encounter the following at different steps and although this may not be applicable right away, the steps are included in advance and summarized here so that you can keep an eye out for it. Different paths and different environments might be slightly different although Gipod levels the playing field a bit.
You can allow cutting and pasting into the window by clicking on Allow
as shown below.
Or allow ports to be opened by just exiting windows that are informational messages about ports like below.
OPTIONAL: In Gitpod, If you prefer "Dark Mode" you can set it in Preferences as shown below.
You can also use editing commands like or (on macs) to Undo for example.
To run the application(s) you need to provide the database credentials.
✅ Step 5a: Note the two values from the downloaded token
Note down the values of Client Id
and Client Secret
from values noted earlier that we will subsequently use for username
and password
in the respective language in a later step.
✅ Step 5b: Download the secure connect bundle
This next step is probably the most involved step in the entire workshop. The goal of this step is to get the customized connect bundle into Gitpod. One of the several ways of doing this is as follows.
Start with the Astra DB dashboard and for the database workshops,
- Click on
Connect
tab. - Click on Connect using any of the drivers
Node.js
(javascript
),Python
orJava
. - Click on
Download Bundle
. - Click on
Secure Connect Bundle
to be able to copy the link locally.
as shown below.
Locate the file locally in the finder/explorer window. Drag and drop the file into the Gitpod explorer window (on the left side, making sure that the cursor, indicating the drop, is positioned in the Gitpod explorer window as shown below.
In the Gitpod terminal window, verify that you dropped the right file and at the top level directory
ls -l /workspace/bootcamp-fullstack-apps-with-cassandra/secure-connect-workshops.zip
If you get a message cannot access
or the file size is not roughly 12K, something may have gone wrong in the process and you need to repeat this step (step 5b).
👁️ Expected output
-rw-r--r-- 1 gitpod gitpod 12261 Jan 12 23:34 /workspace/bootcamp-fullstack-apps-with-cassandra/secure-connect-workshops.zip
TADA your application is configured we can finally play with some code.
✅ Step 5c: Setup the username and password
We have provided some convenience scripts to setup the credentials across all the languages.
As a first step cd
to the week3-app-development
sub-directory with the following command.
cd week3-app-development
Let's start by issuing the following command.
cp .env.sample .env
Open this file and update it by entering the ASTRA_USERNAME
(Client Id
) and ASTRA_PASSWORD
(Client Secret
) values. Values are not shown here. You obtained this in an earlier step.
You may issue the following command in the GitPod terminal window.
gp open .env
You are almost ready to start coding. The next step is to run the convenience script which updates the connection files that you'll be using with the appropriate values. Run the following command
./plugastracreds
Optionally, issue the following command from the Gitpod terminal window if you're interested in knowing what happened behind the scenes/script. Hit space bar to proceed through the changes or hit or q
to exit the command.
git diff
A BIG NOTE OF CAUTION: It's not a good practice to include username, password and other secrets in the source file. Don't ever git commit with clear case passwords, etc. This is done purely for convenience of getting started.
✅ Step 5d: Verify cql access from Gitpod
Invoke cqlsh
as shown below (far right top corner of Gitpod terminal window).
If you completed the earlier steps properly, you should be dropped into the CQL shell as shown below.
Run the following command from the CQL shell of the Gitpod terminal window.
describe keyspaces;
👁️ Expected output
system_virtual_schema system_auth datastax_sla todos
todolist system_views data_endpoint_auth
system_schema system system_traces
FXHtFByhHAjqNjdcLgZNYEll@cqlsh>
We will refer to this as the CQL shell
(cqlsh
) and the original shell as the Gitpod terminal
(bash ..
). You can click on those tabs to switch between the shells.
OPTIONAL: You coud also split terminal
and have both the bash
and cqlsh
side-by-side as shown below rather than clicking on the respective tabs.
TADA! Now you're really done done with the setup and ready to start coding.
Exercises will be different for each language. Pick the language you feel the most confortable with with and JUMP to the respective README.
Sections | Material Description |
---|---|
![]() |
Exercises 6..6f with Java |
![]() |
Exercises 6..6f with Javascript |
![]() |
Exercises 6..6f with Python |
Refer back to the Homework which is required to earn the badges.
Now go ahead and start app dev: Good luck!
You might be eligible for a badge when you attend more workshops and complete the requirements.
Sincerely yours, The DataStax Developers THE END.