Azure Functions is Microsoft’s serverless offering it lets you execute your code in a serverless environment without having to first create a VM or publish a web application.
Azure Cosmos DB is Microsoft’s globally distributed, multi-model database. With the click of a button, Azure Cosmos DB enables you to elastically and independently scale throughput and storage across any number of Azure’s geographic regions.
Step 1: Login into Azure Portal (http://portal.azure.com) and create a new Azure ComsosDBb data as shown below
Step 2: Now once the Azure Cosmos DB database gets created open it and create a collection in it as shown below.
Here you can see as of now it is present at Central India Data Center you can switch on as many locations as you want and Cosmos DB replicates your data transparently all by itself.
Now add a new collection name Conferences as shown below.
Now we can add an entry for a conference in our collection as shown below.
Now we will create Azure Function that will be triggered when we will add new entry in CosmosDB collection.
Step 3: Now go to Azure Portal dashboard Click Create a Resource from left menu search for Function App and click it, you will see the window as shown below fill the function name and other details and click crate as shown below.
Step 4: From your dashboard once this function gets created click on the function tile and open the function, click on the URL , in this case, it is https://conferencefunction.azurewebsites.net/ as shown below, your function app is running now.
Step 5: Now open your Cosmos DB database and click on Add Function as shown below.
Step 6: Now fill your function details as shown below and clicl on Save, and in couple of minutes your function will be created.
Step 7: Now this is how your function appears on the screen.
Step 8: Now open portal.azure.com in the new tab and open your cosmos db , now we will add a new conference in our collection and we can notice it will trigger our Azure Function.
Click on the save and now switch tab where you have your Azure function you will notice that Azure Function gets triggered as shown below.
To Learn more about Azure Functions and Cosmos DB refer following links.