11 Min to complete
In this lesson, you’ll deploy an example application, a simple Tic-tac-toe multi-user game server game, which uses ScyllaDB as a data storage backend.
The lab is based on the Amazon DynamoDB Tic-tac-toe example app project.
You’ll start ScyllaDB by running a single instance using Docker. Please ensure that your environment meets the following prerequisites:
- Docker for Linux, Mac, or Windows. Please note that running ScyllaDB in Docker is only recommended to evaluate and try ScyllaDB. For best performance, a regular OS install is recommended.
- 3GB of RAM or greater for Docker.
- Pip: Package Installer for Python
If you are new to ScyllaDB, it’s recommended to start with the ScyllaDB Essentials course.
Project Alternator is an Amazon DynamoDB-compatible API that allows any application written for Amazon DynamoDB to be run, unmodified, against ScyllaDB. You can deploy ScyllaDB wherever you want: on-premises or on any public cloud. ScyllaDB provides lower latencies and solves DynamoDB’s high operational costs. This lesson provides an overview of the project.
Setting up the Environment and Starting a ScyllaDB Cluster
Note: You can skip this step if you have already completed the Project Alternator Basics lab.
Start a one-node cluster with Alternator enabled
docker run --name some-scylla --hostname some-scylla -p 8000:8000 -d scylladb/scylla:5.0.0 --smp 1 --memory=750M --overprovisioned 1 --alternator-port=8000 --alternator-write-isolation=always
Wait a few seconds and make sure the cluster is up and running:
docker exec -it some-scylla nodetool status
pip install Flask
pip install boto
Run the Tic-tac-toe Application
After all the required packages are installed, download the Tic-tac-toe application:
git clone https://github.com/awslabs/dynamodb-tictactoe-example-app.git
Start the application:
python3 application.py --mode local --serverPort 5000 --port 8000
Open your browser and browse to http://localhost:5000/
Note: Change localhost to the actual public IP if you’re not deploying locally.
Play the Game
Once the browser shows the start page, enter a name, say “user1”, and Log in. This example application does not perform any user authentication. The user ID is only used to identify players.
If this is your first time playing the game, a page appears requesting you to create the required table (Games) in ScyllaDB. Click CREATE TABLE.
In a different browser (or in Incognito mode), browse to http://localhost:5000/ and log in with a different user, say “user2”. This allows you to play against yourself.
Back in the first browser, click Create, enter “user2” as the opponent, and click Create Game!
Refresh the second browser and accept the pending invitation:
Under the Hood
If you have never used the AWS CLI in the past, you need to configure it before you can run it. Any credentials will work as you’re running it locally:
Check which tables were created:
aws dynamodb list-tables --endpoint-url http://localhost:8000
You can see that a Games table was created. Read the data in it:
aws dynamodb scan --table-name Games --endpoint-url http://localhost:8000
This table holds information about the game being played. As the game moves forward, the application stores an attribute for each move played. The name of the attribute is the position on the table.
In this lab, you saw how easy it is to run a DynamoDB application as is, with ScyllaDB as the underlying database.
You can learn more about the code used in this application on the AWS example documentation.