Steve Rich
Created Jun 25, 2025Separating the database from the compute. Creating an Azure Cosmos DB Serverless Instance
In this lab we will continue to use a virtual machine for the compute, but we'll use Azure Cosmos DB for the (noSQL) database. As you'll see later there are various configurations we must do, that are needed for the Python installation. This will give you an appreciation of why many people choose to use containers!
#
Part 2 - Setting up the VM and code
Now I'm not going to show you how to set up a virtual machine for this part. you could refer to the first lab or you could do what I did and use the same virtual machine that I used in the first lab and use it for the 2nd lab.
This part of the tutorial is the most complicated due in part to the setting up that we have to do in this next section.

Now we need to set our environment variables so that the code will connect with our Cosmos DB. We use environment variables to ensure that our connection details are kept private.
You can see in the image below I've typed export COSMOS_ENDPOINT="my URI here" In between the quotes, paste in the URI saved earlier. Remember your URI will be different to mine!

Now let's try the app! Start your app with:
python3 app.py (You can see me doing this in the above screenshot).
Go to the IP address of your VM, with port 8080 on the end

It should work!
Add some tasks

Congratulations!
If you flick back to the Azure Portal and go to your Cosmos DB - and go to Data Explorer, you should be able to see the names of the tasks there, proving they are being stored in the database.
