Azure Function App is an app service that serves as the host construct where functions will be executed and let businesses group functions as a logic unit for easier management, deployment, and sharing of resources.
Why Function App?
The Azure cloud provides this exciting service which is a serverless solution that allows you to write less code, maintain less infrastructure, and save on costs. Instead of worrying about deploying and maintaining servers, the cloud infrastructure provides all the up-to-date servers needed to keep your applications running.
Now let us dive deep into Azure Function Creation:
Login to Azure with your credentials
Search for Function App
Click the ‘Add’ button to create a new function app
Now fill in the details of Subscription, Resource group name, Function app name
Select Code in Publish field and select Runtime Stack, version, Region as shown below and click Review and create
Now wait for a while to validate your function app once validation completes clicking on the ‘Create’ button, will initialize your deployment.After deployment, go to your function app, you can see configuration settings on the left side of the main page. Go to Identity and select System assigned Identity Status to On and click the save button.
A system assigned managed identity is restricted to one per resource and is tied to the lifecycle of this resource. You can grant permissions to the managed identity by using Azure role-based access control (Azure RBAC). The managed identity is authenticated with Azure AD, so you don’t have to store any credentials in code.
Now click on Azure role assignments and select the subscription (if you have many) and provide an appropriate role to the function app as shown in the below image and click the ‘save’ button.
Now go to the main page, you can see the function blade on the left side of the page click on functions -> Add -> Develop environment as Develop in the portal and select HTTP Trigger and scroll down to provide the function name and Authorization level.
Authorization level controls whether the function requires an API key and which key to use; Function uses a function key; Admin uses your master key. The function and master keys are found in the ‘keys’ management panel on the portal when your function is selected. For user-based authentication, go to Function App Settings.
Click on Add will initialize the deployment of your function.
Click on Code + test blade and replace the existing code with the below code and save it.
# Input bindings are passed in via param block.
# Write to the Azure Functions log stream.
Write-Host"PowerShell HTTP trigger function processed a request."
# Interact with query parameters or the body of the request.
The above code will give you the details of the Virtual Machine, so to make the function work we need to create a Virtual Machine.
Now click Test/Run now it will popup for input, click on Add Query parameter and provide the values as below, here I have given the values of my resource group.
Now click the ‘Run’ button to run your function and wait for a while to make things visible to you about the details of your Virtual Machine in the response body of the function like in the below image.
The main highlight use of Azure Functions is that you can write the code easy to use web interfaces and build and debug them locally on your machine of choice. And it lets you leverage the same function code on other targets – IoT Edge, Azure Stack, Cloud Service, etc.
Drop a comment and share your feedback. If you have any queries, I will be happy to reply.