Application development
.NET Core Azure Azure App Services Azure Function Azure Storage Blob Trigger PaaS Visual Studio

How to Create Azure Blob Trigger Functions

Welcome to today’s post.

Today I will discuss how to create an Azure Blob Trigger Serverless function.

Before I provide the overview on how Blob Trigger functions are created, I will also explain what they are. I will then discuss some uses for Blob Trigger functions.

In previous posts, I showed how to create Azure Serverless functions in .NET Core applications. I also showed how to deploy Serverless functions to Azure under a consumption plan.

What are Azure Functions?

The unique aspect of Azure Functions is that they are serverless. I will explain some of the benefits of being serverless.

Unlike Azure Virtual Machines (VMs), that we could also use for our computation needs, with serverless functions we are not concerned with provisioning servers, memory, CPUs, hard disks, and so on. All the server hardware and resources are catered for with Azure Functions. We just create one and pay based on our consumption.  

What this means is that you only pay for consumption of compute resources. When we create an Azure Function in the Azure Portal and select a plan, either a consumption or a premium plan. With a consumption plan, you get a free allocation/grant of 1 million function executions per month and an allocation of execution time. After that, it is pay as you go on a GB/s execution time and a cost per million executions. With a premium plan, it starts off as pay as you go based on CPU and memory duration per hour.

In addition, when we create a new Azure Function, a storage account is created by default. In addition to the consumption charges of the Azure Function, we are also billed for use of the storage account, which are separately billed.

What are Blob Trigger Functions?

Blob Trigger functions are function that is run under a serverless Azure Function.

Blob Trigger functions are one of the available types of trigger functions that can be created in Azure. These include:

  • Blob trigger
  • Http trigger
  • Event Hub trigger
  • Queue trigger
  • Service Bus Queue trigger
  • Service Bus Topic trigger
  • Timer trigger

As the name suggests, Blob triggers contain trigger functions that are executed when an event occurs within a Blob. When a Blob is uploaded to the storage account within the Azure Function, the Azure Blob trigger function is executed.

What are some of the uses of a serverless trigger function in Azure?

  1. Upload data to a database from a new file uploaded into an Azure container blob.
  2. General database housekeeping.
  3. Process and cleanse new files before loading into a data warehouse.

With Blob trigger functions, there is no need for a dedicated web or application server with hardware storage to store our Blobs and the overhead of managing the server hardware resources and storage.

In the next section I will explain how to create the Azure Blob Trigger function.

Creation of an Azure Blob Trigger Function

To create a Blob Triggered Azure Function, I will show how I used Visual Studio to achieve this.

Open Visual Studio.

Create a new project.

Select Azure Function. On the following property page, select Blog trigger as shown:

Next, select the storage account, connection string and path to the blob file:

Select the storage account, paste in the Azure storage connection string, and a path.

The path is the unique path to the container folder containing the files to monitor. It can be modified in the generated function declaration later.

If the path to the file in your container is in the same root folder as the container, then the path is:

[container-name]

If the path to the file in your container is in a subfolder, data under the same root folder as the container, then the path is:

[container-name]/data

In the generated code, there is a configuration file, local.settings.json. Add a connection string for your Azure storage:

To integrate this connection string in your settings to your trigger method, the BlobTrigger attribute declaration in the static Run() method needs to have its Connection property to the connection string key as shown:

Next, to integrate the blob folder that will be monitored to the event trigger, set the path as shown:

The format of this path was mentioned earlier when setting initial values of the project.

We now build the project.

Now try publishing the Function App to Azure.

In Manage Settings in the Publish dialog, notice that any keys within the values node in the local settings configuration will be shown:

After the function is published successfully, you will notice the extra connection string has been migrated to the Function App’s Application Settings as shown:

In the above overview, you have seen how to create and configure an Azure Blob Trigger function.   

In future posts, I will show how to troubleshoot and test triggered Azure Blobs Functions.

That’s all for today’s post.

I hope this has been informative and useful.

Social media & sharing icons powered by UltimatelySocial