Azure Function Apps

Azure function app is used for hosting a function i.e. code which consists of few lines for some functionality.For hosting a function we do not need a Virtual machine. Function apps can be hosted on Azure without a virtual machine so we do not need a service plan for function apps. Azure will charge only when code executes.

Add Function App

Login with credentials in Azure Portal. Click on Function App in left menu as shown below, it will display Fucntion app list page , from there click on Add button:

Function App Menu

Below is the page for creating function app:

Here I have selected an existing resource group ‘LogixnResource’. I have entered name of function app, it should be unique.Since we are going to deploy code so code should be selected in Publish type. I have selected .Net Core and version 3.1. Click on Hosting tab and select as per below screenshot:

Storage account is required to store the function so a new storage account will be created. Plan type is ‘Consumption(Serverless)’ , it means we do not require a dedicated virtual machine and based on number of requests to our function app, azure will allocate resources. If your function app requires more resources then you need a dedicated virtual machine and your plan type should be ‘App Service Plan’ and you need to create a new service plan.

Click on ‘Review+create’ button after that click on ‘Create’ button. Now our function app is created in Azure, now we will add some code to make it working.

Add Code in Function App

We will use Visual Studio 2019 for writing the code of function app, you can also use Visual Studio 2017. Please make sure that Azure development workload is installed.

Select Azure Functions project template and create a new project.

Azure Functions Template

Select Http Trigger on next screen, we want our function to be invoked by http request. Click Create button. I have changed default sample code , I have added code to show DateTime of Server where code is running.

public static class Function1
    {
[FunctionName("Function1")]
public static IActionResult Run(
HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req)
{
string responseMessage = "Current Date and Time on server is :" + System.DateTime.Now.ToString("dd-MM-yyyy HH:mm:sss");             
 return new OkObjectResult(responseMessage);
  }
}

You can also debug in local environment. Right click on project and select publish. After that a screen will appear where we can select Azure Functions Consumption plan, select existing option and click on ‘Create Profile button’, below screen will appear, here you have to login with azure portal credentials :

Publish Function App

Select the function App ‘logixnfunctionapp’ which we have created on Azure portal and click on ‘OK’ button. Click on ‘Publish’ button on next screen, after this publishing will start.

Visit function app section in Azure portal again and expand Functions. Function1 is the code which we have just published from Visual Studio.

Published Function App

Click on Get function URL link as shown is above screenshot, below is the URL:

https://logixnfunctionapp.azurewebsites.net/api/Function1?code=QeNCReL7xaa2nVNE/13LvsRrqPKHRXa6V7jwOTuAllWH34fdJTaB2Q==

Paste this URL in browser , http request will be sent to our function app and it will be invoked, result will be displayed on browser:

Function App Output

In this article we have seen steps for creating and publishing Azure Function App. There will be multiple articles published for Azure. Please like our Facebook page for getting new posts update.
https://www.facebook.com/logixn
My Facebook group:
https://www.facebook.com/groups/software.development.posts

Leave a Comment

Your email address will not be published. Required fields are marked *