Create Azure Function – Cosmos Trigger in Azure Portal

Introduction

This article will help you learn how to create Azure Function – Cosmos  Trigger in Azure Portal.

Before reading this article, please go through some important articles mentioned below,

  1. Exploring About Azure Function
  2. Create Http Trigger Azure Function In Azure Portal
  3. Create The Timer Trigger Azure Function In Azure Portal
  4. Create Durable Function In Azure Portal
  5. Create Durable Function In Visual Studio
  6. Create Azure Function In Visual Studio
  7. Create Azure Function - Blob Trigger In Azure Portal
  8. Create Azure Function - Queue Trigger In Azure Portal
  9. Create Azure Function - Timmer Trigger In Visual Studio

Azure Function

 Azure Functions is a serverless computing service and is hosted on the Microsoft Azure public cloud. It is designed to accelerate and simplify application development. The cloud provider takes care of all the headaches of running the server, dynamically managing the resources of the machine, etc. It also provides auto scalability.

Serverless applications, also known as Function-as-a-Service or FaaS, is an offering from most of the enterprise cloud providers in which they allow the users to only write code, and the infrastructure behind the scenes is managed by them.

Azure Functions is the event-based serverless application framework which can automatically scale up and down based on the executions that are being triggered. This Microsoft Azure service allows you to run small pieces of code in Node.js, C#, Python, PHP and Java without any infrastructure configurations.

Here, we will see about Azure Function.

Purpose

Azure Functions lets you execute your code in a serverless environment without having to first create a VM or publish a web application.

Key Features

  • Intuitive, browser-based user interface - You can write code in the easy-to-use web interface.
  • write code in different programming languages
  • pay per function execution
  • parallel execution when multiple triggers occur
  • Supports Continuous Deployment and Integration

Cosmos DB

Azure Cosmos DB is a fully managed NoSQL database for modern app development. Single-digit millisecond response times, and automatic and instant scalability, guarantee speed at any scale.

Create Azure Function - Cosmos DB Trigger in Azure Portal

Prerequisites

  • Microsoft Azure Account.

Follow the below steps to create an Azure Storage Account.

Step 1

Log in here. Please go through the article mentioned below for creating an Azure Function.

Cosmos DB Trigger

Step 2

Enter the details for fields - choose the subscription, resource group, function name, run stack, version and region. Let's see each, one by one.

 Cosmos DB Trigger

Step 3

After successfully creating the Azure Function services, you are land over to the overview page as shown below.

Cosmos DB Trigger

Step 4

Next, we have to Create Cosmos DB account.

Cosmos DB Trigger

Choose SQL API and Enter the values and click on create

Cosmos DB Trigger

Once it is created, the windows like this

Cosmos DB Trigger

Step 5

Now, open the function service and choose Function under the Function tab. Now click on Create option to create a function trigger.

Cosmos DB Trigger

Step 6

In this blade, you can able to see many triggers. Search for Cosmos DB trigger function here.

Cosmos DB Trigger

Enter the values

  1. In that, we need to give the function name
  2. choose Cosmos DB Connection
  3. Enter Database name
  4. Enter Collection name

Now, just view code+Test for Queue trigger function.

Cosmos DB Trigger

Open the log and check its connected

Cosmos DB Trigger

Step 7

Now, we need to create a database in Cosmos DB account for getting the log details in functions. So, move to CosmosDB account.

Then, click on Data Explorer and choose sample DB

Cosmos DB Trigger

Its looks like this window.

Cosmos DB Trigger

Next, click on New item

Cosmos DB Trigger  

Now, Add your data and click the save button

Cosmos DB Trigger

Now it added to the database

Cosmos DB Trigger

Output

Now, move to functions and open the logs. we can successfully run our CosmosDB storage trigger function here. The output will look like this.

Cosmos DB Trigger

And also we can check Total execution under the overview

Cosmos DB Trigger

Summary

I hope you understood how we can create a CosmosDB trigger function in the Azure portal. Stay tuned for more articles on Azure Function.


Similar Articles