Creating Azure Functions with Visual Studio Code.


In this article, I will explain how we can use Visual Studio Code and the Azure Functions Core Tools to develop Azure Functions. You maybe know about the Visual Studio Code Editor, which has exploded in popularity in recent years. It's completely free and open-source, and cross-platform, so you can run it on Windows, Mac OS, and Linux. It's particularly popular among web developers, and it has a huge ecosystem of extensions that bring in support for all kinds of different programming languages, as well as integration with cloud providers like Azure.

Step 1

To develop Azure Functions in Visual Studio Code We need to install Azure Functions core tools that are available on GitHub. There is a documentation with required installing instructions for Windows, Mac OS, and Linux. On Windows, we can choose version 1 or version 2 Azure Functions run time. But other operating systems are supported only version 2 Azure Functions run time. Here I am using version 2 run time of npm Azure functions core tools on Windows. Hence they are cross-platform, you can use the exact same commands on Mac OS and Linux.


Step 2

Next, open your Visual Studio Code and install Azure Functions extension. Azure Account extension will be installed automatically with Azure Functions extension. Now you can see the Azure logo on the left side of the Visual Studio Code.

Step 3

Click the Azure logo and create a new Azure Functions project.

This gives you a choice of three run times dotnet, node and java. I am going to choose JavaScript. You can choose your preferred run time.
Now you can see host json file, local.settings.json file,gitignore file and vs code folder in the created Azure Functions project.

Step 4

Let's add our first Azure Function to the newly created project. Then go to Visual Studio Code Azure view and click the Azure Functions icon to create a new Azure Function.



We can choose a variety of languages and templates. let's create an Http trigger JavaScript function.


We need to give it a name, and access rights. I am going to name it as a Test with Anonymous access rights.


Now you can see that it's created an index.js file containing the JavaScript for our function and a function.json file, as well as sample.dat 


Step 5

Let's debug the Test Azure Function Pressing F5 key. We will need to wait a moment for the Functions run time to initialize, and for the Visual Studio Code debugger to attach to the node process. You can add breakpoints if you want.
I am going to send a post request for the newly created Azure Function endpoint using Postman. You will be able to see the following response.

Step 6

Now you can deploy your application to Azure portal using Visual Studio Code. First, click the deployment button in the Azure Function extension.
Then log your Azure account via Visual Studio Code after that add required details and configurations in the deployment process. Those details and configurations are related to your Azure account. Finally, you will be able to successfully deploy your application to the Azure portal.

Comments