Azure – Create Basic Azure Function
Today we will continue with one new service provided by Azure. In this blog we will explore about Function Apps in Azure. Azure Functions run inside Azure app service Function Apps and are very powerful. Azure Function is a solution for running small piece of code or a “Function” in cloud without hassle of managing the web servers or containers. So that’s why we can say, it has server less architecture. It lets you run small pieces of code and the developer doesn’t have to worry about the infrastructure of the platform on which it is executed.
With the Azure Functions we can develop and test our Azure Functions locally. And when we’re done, we can publish them to Azure
In this blog, we will create a simple Azure function example and will do a small modification to it and see the result. Later I will post a separate blog Azure – Access Azure SQL Database From Azure Function, where we will see, how to interact with Azure SQL database using Azure Function.
Let’s start with our simple Azure function. Following steps need to be follow to achieve the goal.
- Connect to your Azure portal dashboard using your subscription account. If you don’t have any subscription, in that case you can get trial Azure subscription with one-month of validity. Then you can connect to the azure portal dashboard as in following figure.
- To create new Azure Function, click on Create a resource Link and then search for Function App. Select the Function app from search result and then click on the link.
- Click Create button to start with creating Azure function app as shown in following figure.
- It will allow you to fill the required information to create a new Azure function app as shown in following figure. We need to fill all required information and click Create to create the function app successfully and the app details will be shown.
- The above point is , if we are creating a new Azure Function App but if we have already created our Azure Function App and we want to add function to thte existing Function app then to verify/check our existing Azure function app, click on All service link (Marked in red rectangle in above figure) to go to available Azure services page and then click Function App Service link as shown in below figure.
- Once click on Function Apps link, it will show all our existing Azure function as shown in following figure.
Now time comes to add our functions to the function app. There are many options/templates available to create azure functions as per the scenario, requirements and the way we want our function should trigger. Some of them shown in following list.
- Http Triggers
- Timer Triggers
- Event Hub Trigger
- GitHub Web hook
- Cosmos DB Trigger
- Blob Trigger
- Queue Trigger
- Service bus Queue Trigger
In this example we will go with Http Triggers option and will create a very simple function. Expand your function app andclick add image to add a new function. Then choose webhook+Api and language C# click on Create this function as shown in following figure.
- One the function added successfully, we will see the following screen with c# code.This is a predefine function with out of box code. We can modify the code as per our requirement. Here we will do a little modification to the existing code and add a extra string to the existing message like “Your office time is from 8.30 am to 5.30 pm” as shown in the following figure.
- Now time comes to test the function. For that we need the function URL so that we can trigger the function by http request. We can copy the URL by clicking Get function URL on the right top corner of the screen.
- Once we copy the function URL, modify it by passing one query string to the function as it is a parameterised function. So, append this “&name=Manas” at the end of the URL and before hit enter and see the following result.
Figure 1: Azure – Azure Portal Dashboard
Figure 2: Azure –Find Azure function app and start with create a new function.
Figure 3: Azure –continue with create a new function.
Figure 4: Azure – Fill all required data to create a new function.
Figure 5: Azure – Go to Azure Function Apps
Figure 6: Azure – List of existing Azure function apps
Figure 7: Azure – Add new function to our Azure app
Figure 8: Azure – Function HttpTriggerCSharpGetscreated
Figure 9: Azure – Get Azure function url.
Figure 10: Azure – Response of the Azure function.
Thanks for reading
Keep reading, share your thoughts, experiences. Feel free to contact us to discuss more. If you have any suggestion / feedback / doubt, you are most welcome.
Stay tuned on Knowledge-Junction, will come up with more such articles