Azure Functions let us execute small pieces of code or function in a serverless environment as a cloud function. You just need to focus on code and functionalities rather focusing on cloud infrastructures or any other aspects of the cloud solution. You can create Azure Function directly from the Azure Portal. Azure Functions Tools for Visual Studio also lets you develop, test, and deploy functions to Azure. Having it developed in Visual Studio gives lots of other flexibility to the developers as well, where we can leverage all the IDE features including source control integration, testing, and other aspects.
Azure functions getting started with visual studio
Let’s learn how we can create a simple Azure Function and deploy it to Azure using Visual Studio.
Start a new instance of Visual Studio and select Azure Functions available under Visual C# Project Template from the New Project Dialog Window.
While creating the project, make sure you select “Create new Git repository” option, so that newly created projects added to local git repository as well. If you are wondering how it works – Read one of my previous posts – Create New Git Repository While Creating New Project in Visual Studio
Next dialog window for Azure Functions will ask several options such as Azure Function Versions, Types etc. For now, choose Http Trigger, and Set the Access Rights “Anonymous”. Make sure the version of Azure Function is set to v2(.NET core)
Click on Ok.
Visual Studio will take a while to setup and create your Azure Function. The current solution has a function named “Functon1” which takes arguments name and display the same. Just like a simple RestAPI Call, where you can just invoke the method.
As of now, let’s not change anything to the code, and Run the functioning app from Visual Studio by just pressing F5.
When the Function is running, you can access the Http EndPoint and pass on a parameter to test it out.
Which means our function is working fine. Feel free to place a breakpoint in the code and check how the code flow and internal execution is.
When everything is working fine, push your code to your GitHub account.
You may ignore this step; however, we will refer this code base in the next post.
In the next step, we will publish the Azure Function
In Solution Explorer, right-click the project and select Publish. Choose Publish option again and then click on Start.
Select “Azure Function App” and then select “Create New”.
Then provide required details for App Services and finally click on Publish.
Visual Studio will take a while to create all the Azure resources and publish your code. Once the Publish is completed, you can open the deployed url from Visual Studio.
Now, you should be able to access your function from the deployed version of Azure Function.
Open the Azure Portal and navigate to the Azure Functions Resource and explore your function from there.
If you already created the Azure function from the Azure Portal, you must be familiar with this. To monitor logs, success count and errors, navigate to Monitor option available under Function1
You can also integrate your Azure Function with Azure Application Insights for better telemetry and monitoring
There are several types of Azure Functions with different types of triggers, you can now explore them. This post is all about a quick walkthrough on how we can create Azure functions from Visual Studio. We will cover some more detailed topics in the subsequent posts.
Pingback: Generate the OpenAPI definition for Azure Function Apps - Daily .NET Tips