Design and Develop Azure Function App

Title: Design and Develop Azure Function App

Introduction: All my articles are compiled into simple steps with detailed screen shots and elaborative description. By following these steps even, a novice programmer should be able to replicate scenario. Please go through the steps and provide your valuable feedback to make my next articles more clearer and intent.

Note: I took help of various internet sources while researching this item. Credit goes to internet and Microsoft communities. This is one of the topics in Azure certification.

This is my 12th article on Azure.

Please follow below links for my previous Azure articles

Azure WebApps

Azure Logic App

Azure Event Grids

Azure SQL

Azure AD MSAL

Azure AD and User Management

Azure Key Vault With Logic App

Azure Key Vault With Data Factory

Accessing Azure Blob Containers

Working With Azure MSMQ

Key Vault & Secrets

Follow below mentioned 22 steps to Design and Develop function app which access storage account.

 After completing this blog, you will be able to do

  • What is Azure function app
  • Various commands being used in function app
  • Various classes and name spaces being used in function app

What is function app?

A function app lets you group functions as a logical unit for easier management, deployment, scaling, and sharing of resources.

Sample Description: Create a storage account and upload a json file. Design and develop a function app which reads json file and displays

Step 1: Open Azure portal (https://portal.azure.com)

Step 2: Create a storage account as shown below

Step 3: Access storage account created in previous step. Go to Access Keys blade and collect connection string. This connection string will be used in next steps.

Step 4: Create blob and upload a json file. Function app we creates in next step will read this json file.

Step 5: Create a function app in portal as shown below.

Step 6: In next steps we are going to work on code part. Open visual studio and create function as by using below command.

func init –worker-runtime dotnet –force

Step 7: Open local settings file and update value of “AzureWebJobsStorage” property with the connection string we collected from storage account

Step 8: Now add a function trigger by executing below command

func new –template “HTTP trigger” –name “MatetiTrigger”

What if function Trigger? -Triggers will initiate the function app. Every function app must have at least one trigger. Triggers have associated data, which is often provided as the payload of the function.

Step 9: Open newly added Trigger file and delete entire code in it. Then add below name spaces.

using Microsoft.AspNetCore.Mvc;

 using Microsoft.Azure.WebJobs;

 using Microsoft.AspNetCore.Http;

 using Microsoft.Extensions.Logging;

Step 10: Update Trigger file as shown in below image.

Step 11:Now its time to test our trigger.We will use HttpRepl to test it.

What is HttpRepl?- The ASP.NET team has built a command-line tool called HttpRepl. It lets you browse and invoke HTTP services in a similar way to working with files and folders. You give it a starting point (a base URL) and then you can execute commands like “dir” and “cd” to navigate your way around the API. HttpRepl stands for HTTP Read-Eval-Print Loop

Step 12: Deploy function app locally by using below command

Func start –build

Above command will deploy function in local host (http://localhost:7071)

Step 13: Open another instance of visual studio code and launch the terminal.

Execute httprepl command to test function app using repl

Httprepl http://localhost:7071

Then navigate to api and matetitrigger by using cd command. Using post command post data to api.

Please observe below image.

Step 14: Create another trigger of type Timer as shown below

Step 15: Change Timetrigger parameter in run method and your code should look like below. You changed timer trigger to initiate for every 30 seconds

Step 16: Start function locally and observe the output window. For every 30 seconds the Timer trigger will invoke

Step 17: Now create another http trigger to get information by using below command

func new –template “HTTP trigger” –name “InfoTrigger”

Step 18: Open InfoTrigger.cs and modify the code as shown below. Add required names spaces.

Install below command

dotnet add package Azure.Storage.Blobs –-version 12.6.0

Below code is trying to connect the blob we created in previous steps and reading mysettings.json file content. This method is returning the content of json file.

Step 19: As the blob is showing error, we need to install bolb package by using below mentioned nuget package.

func extensions install –package Microsoft.Azure.WebJobs.Extensions.Storage –version 4.0.4

Step 20: Now deploy function locally by using “func start –build” command and test it using repl

Step 21: As the function is working properly in local, its time to deploy it in azure

Login to azure and execute below command

func azure functionapp publish matetifunctionapp

Step 22: Login in to azure and test the function app. It should display the content of json as shown below.

Azure function has been deployed successfully which is accessing blob storage and displaying information.

Happy Coding!!!

3 thoughts on “Design and Develop Azure Function App

Leave a comment