Coding Azure functions using VS Code
Creating an HTTP trigger Azure function using VS Code involves several well-defined steps. Here is a detailed guide to help you through the process.
There are some prerequisites to enable the development of Azure functions using VS Code, as follows:
- Ensure you have VS Code installed on your machine. The use of VS Code will help you not only develop the Azure functions needed but also manage your Azure account using the Azure Tools extension.
- It is recommended that you sign in to your Azure account to create the new function. The C# Dev Kit may also be installed.
- The GitHub Copilot extension can also be installed to help you solve coding problems and, at the same time, guide you while writing code.
- Install the Azure Functions extension for VS Code. This VS Code extension will facilitate the development of functions, giving you wizards for each function trigger desired.
- Install the Azurite extension for VS Code. This VS Code extension is an open source Azure Storage API-compatible server for debugging Azure Functions locally.
- Make sure you have the Azure Functions Core Tools, and the .NET SDK installed if you are using C#.
Once you have set up your environment, you will have something like the following figure:

Figure 1.6: VS Code ready to write Azure functions
- Once all the prerequisites are set, in the Azure tab, go to WORKSPACE and select Create Function Project…. Next, perform the following steps:
- Choose a location for your project and select your preferred programming language.
- Follow the prompts to create a new HTTP trigger function. You can name it
Health
and call the namespaceCarShare.Function.
- You will need to decide on the access rights for this function. For this example, you can choose Anonymous. We will discuss each of the security options later.
- Open the newly created function file. You will see a template code for an HTTP trigger function.
- Modify the function to meet your specific requirements, which, in this case, means to respond if the function is working properly. Notice that this is a
GET
andPOST
function. For the purpose we have defined, you can change the code to only be an HTTPGET
function. - Save your changes.
For running and debugging locally, you just need to press F5 or navigate to Run > Start Debugging. VS Code will start the Azure Functions host, and you will see the function URL in the output window. Then, you can use tools such as Postman or your browser to send HTTP requests to your function endpoint.
It is worth mentioning that for running Azure Functions locally, you will need to allow PowerShell scripts to run without being digitally signed. This can be a problem depending on the security policies provided by your company.
Once the function is running, you can consider it the same as when you work on other types of software projects, and even the debugging will work properly. The trigger will depend on the function you set. The following figure shows the code of the function program, where you can see the response to the caller with a status of 200
by using OkObjectResult
with the message “Yes! The function is live!” and the UTC time.

Figure 1.7: Azure Functions running locally
As you have created a function app connected to a GitHub repository with the deployment process handled by GitHub Actions, once you commit and pull the code to GitHub, GitHub Actions will automatically build the function and deploy it as a function app.

Figure 1.8: Function app deployed using GitHub Actions
It is not the purpose of this book to discuss CI/CD strategies, but you will certainly need to think about them when it comes to professional development.
The result of this deployment can be checked in the Azure portal, where the function developed will be available in the list of functions. It is worth noting that a function app can handle more than one function at the same time.

Figure 1.9: Health function available in the function app
The function can be executed as soon as it is published to Azure. As a result of the sample function, as this was developed as a GET
HTTP trigger, we can check that the function is working by accessing the API in the web browser.

Figure 1.10: Health function running properly
As you don’t have a live CI/CD pipeline, you can also publish your Azure function directly from the VS Code IDE. To do so, you may use the Azure Functions extension provided by VS Code.
There are a few steps to follow in this case. The first one is to select the action to deploy the function in the VS Code prompt:

Figure 1.11: Deploying to Azure using VS Code
After that, you will need to select the corresponding subscription and the name of the new function app you want to deploy, considering a new function:

Figure 1.12: Creating a new function app
The current process proposed by the extension is to deploy an Azure function in the Flex Consumption plan. There are some specific locations where this option is available:

Figure 1.13: Defining the location for the new function app
The definition of the runtime stack is also important to get the most out of your Azure function. In the case of the Flex Consumption plan, you will also be asked for the memory usage in the instance and the maximum number of instances available for parallel calls.

Figure 1.14: Defining the runtime stack for the new function app
Once these sets are defined, your Azure function will be deployed correctly. You can also redeploy functions using the same technique later, without needing to recreate the Azure function app every single time.

Figure 1.15: Function app properly deployed
Last, but not least, the Azure portal also gives you the possibility to monitor and manage the functions deployed. Once this process is done, you can monitor your function’s performance and log. By using the Monitoring section of your function app, you can view execution details, track failures, and analyze performance metrics.