Introduction to Cosmos DB
Introduction to Using Cosmos DB
Introduction to Creating an App with Cosmos DB
The course is part of these learning pathsSee 1 more
Cosmos DB is one of many database solutions in a crowded market. From DynamoDB to Cassandra to CockroachDB, the questions one would naturally ask when examining Cosmos DB are, “what makes it special and how can I get started with it?”
This course answers both of those questions as thoroughly and concisely as possible. This course is for anyone with an interest in database technologies or creating software using Microsoft Azure. Whether you are a DevOps engineer, a database admin, a product manager, or a sales expert, this course will help you learn how to power your technology with one of Azure's most innovative data solutions.
From this course, you will learn how to make use of Cosmos DB's incredible flexibility and performance. This course is made up of 9 comprehensive lectures to guide you from the basics to how to create your own app using Cosmos DB.
- Learn the basic components of Cosmos DB
- Learn how to use Cosmos DB via the web portal, libraries, and CLI tools
- Learn how to create an application with Cosmos DB as the data backend
- People looking to build applications using Microsoft Azure
- People interested in database technologies
- General knowledge of IT architecture
- General knowledge of databases
It's been a long road but here we are finally at the culmination of all we've studied in this course, the final instructive lesson on Cosmos DB. If you've been following along carefully you will have done or at least know how to do the following: Set up an Event Hub in your Azure account, set up an Azure Function that responds to events in your Event Hub and then saves the events to Cosmos DB, and finally, set up the Cosmos DB endpoint that the Azure Function intends to utilize.
So in theory, we're already done, we're at the finish line. But before we can start giving out the high fives, we need to validate that everything works. How can we go about proving that our simple app actually works?
Well, consider this: if everything works as expected, all we should really have to do is send an event to our Event Hub. The Azure Function we defined should be triggered by this and automatically execute thereby sending the data to Cosmos DB. So validation is simply sending the event and then checking to see if the data was saved in Cosmos DB.
Let's start with the sending. How do we get a message to our Event Hub? Well, if you take a look at the Event Hub documentation, you can see that there are actually several ways. We can use the Event Hub library with the programming language of our choice and write some code that sends the message. We can also use Powershell or the Azure CLI tool. We will provide links for all the relevant documentation as explaining exactly how to use the different SDKs and CLI tools for Event Hub is out of scope for this course (https://azure.microsoft.com/services/event-hubs).
But perhaps the easiest way to test if you don't wanna write a lot of code would be to use Event Hub's REST API with cURL. As long as the message is properly constructed, you should be able to send your message with one command.
We can check the message using Azure Data Explorer. Click on the relevant Cosmos DB account name and find the collection you used. Since we're doing the MongoDB API, we can just do a simple select star query and we should see the JSON document we sent.
If you don't see the message saved in your Cosmos DB account, don't panic. It's most likely a simple error or like a typo or something. So first just make sure the message is actually reaching Event Hub. You can verify this in the web console and checking the Event Hub dashboard and logs. Azure Functions also log their usage history, so make sure your message is getting at least that far. Make sure the Azure function's executing.
If you don't see any traffic hitting Event Hub, it means that your send command is failing somewhere early. You may have the wrong endpoint or the wrong URL set. Now, if you see the message in Event Hub but the Azure Function is not triggering, check your Azure Function's function.json file to ensure that the Event Hub trigger is set properly. And finally, if you see that the Azure Function is being called but no data is being sent to Cosmos DB, double-check both your Python code and the function.json again. Your output binding may have the wrong name or your Python code may have a bug in it. Once you isolate exactly where your app is failing it becomes much easier to resolve the problem.
Hopefully, you are able to successfully complete this end-to-end test. If you get stuck and troubleshooting doesn't help, feel free to start over. Recreating these Azure resources should not take very long. Reviewing the Azure documentation can also help. To those people who successfully get everything working, congratulations! You are on your way to becoming a true Cosmos DB Maven. The next and final lesson will conclude the course with a brief review and some additional info. Thanks again for persevering this far, cheers.
About the Author
Jonathan Bethune is a senior technical consultant working with several companies including TopTal, BCG, and Instaclustr. He is an experienced devops specialist, data engineer, and software developer. Jonathan has spent years mastering the art of system automation with a variety of different cloud providers and tools. Before he became an engineer, Jonathan was a musician and teacher in New York City. Jonathan is based in Tokyo where he continues to work in technology and write for various publications in his free time.