Welcome to today’s post.
Today I will discuss how to create an Azure Blob Trigger Serverless Function.
What are some of the uses of a serverless trigger function in Azure?
- Upload data to a database from a new file uploaded into an Azure container blob.
- General database housekeeping.
- Process and cleanse new files before loading into a data warehouse.
To create a Blob Triggered Azure Function, I will show how I used Visual Studio to achieve this.
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:
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:
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:
That’s all for today’s post.
I hope this has been informative and useful.
In future posts, I will show how to troubleshoot and test triggered Azure Blobs Functions.
Andrew Halil is a blogger, author and software developer with expertise of many areas in the information technology industry including full-stack web and native cloud based development, test driven development and Devops.