Are you looking to deploy your code on Azure Cloud without provisioning a Virtual Machine or a Server by yourself? Then, Azure Function is the solution. Azure Functions are similar to AWS Lambda and Google Cloud Functions.
Azure Functions allows you to run small pieces of code (called “functions”) without worrying about application infrastructure. With Azure Functions, the cloud infrastructure provides all the up-to-date servers you need to keep your application running at scale. A function is “triggered” by a specific type of event. Supported triggers include responding to changes in data, responding to messages, running on a schedule, or as the result of an HTTP request. Also, it allows you to write code in various languages, such as C#, JavaScript, Java, Python etc.
In this post, we will create an Azure Function using Visual Studio Code. We will use HTTP trigger and Python as language.
Note: At present, Python Azure Functions cannot be edited in browser and have to be modified locally and then deployed to the serverless environment of Azure Functions.
Pre – requisites:
- An Azure Account with a Subscription. You can create an account on Azure with 1 month Free trial (subscription), but you need a credit card for payment information (you will not be charged until you opt to upgrade your account after 1 month).
- Visual Studio Code installed in your system (Laptop/PC).
- Python 3.8, Python 3.7, Python 3.6 installed in your system.
- Node.js installed in your system. It is required for NPM. You can see, if it is already installed in your system by running command node –version.
Step 1: Install Azure Functions Core tools
1. Open Command Prompt. Run command given below to check, if node (npm) is already installed or not. If command fails to run, then install Node.js.
node --version
2. Once Node.js install is confirmed, run the command given below to install Azure Functions Core tools.
npm install -g azure-functions-core-tools


Step 2: Install VS Code Extensions
1. Open Visual Studio Code.


2. Select Extensions tab from left sidebar. In EXTENSIONS: MARKETPLACE area, search for Python and Azure Functions , install them and then enable them. (Both the extensions are provided from Microsoft, Azure Functions extension is dependent on Azure Account extension which will be installed automatically).




3. After Azure Function extension is enabled, Azure icon will appear in left sidebar.


Step 3: Create a Function
In this part, we will create an Azure Function with Python as language and HTTP as trigger. We will explore Azure Functions in detail in another post.
1. Select Azure tab from left sidebar. Then, in the AZURE: FUNCTIONS area, select the Create new project… icon.


2. In the Folder Selection prompt, create or select a new folder for your project.
3. In the subsequent prompts, provide the information as described in table below.
Field | Value |
---|---|
Select a language | Python |
Select a Python interpreter to create a virtual environment | Select the python installed in your system |
Select a template for your project’s first function | HTTP trigger |
Function Name | Provide a function name of your choice like ‘AzureFunctionCreateDemo‘ |
Authorization level | Anonymous With this option anyone will be able to make a request to this function, no authorization required |
Select how would you like to open your project | Add to workspace |












4. Using the above information, Visual Studio Code generates an Azure Functions project with an HTTP trigger. Once the project is created, you can view the local project files in the Explorer.


5. We will learn about these files in detail in another post. The current sample code expects a name parameter in request and will respond with string “Hello, {name}. This HTTP triggered function executed successfully.”
Step 4: Run Azure Function locally
Instead of running your function code directly in cloud. You can run and test it locally using Azure Functions Core tools which we installed using NPM.
1. Press F5 to run the project locally.
2. If you did not execute Step 1, you will be prompted to install Azure Functions Core tools. If already installed, your app will start in terminal. It will install dependencies mentioned in requirements.txt file and then you can see the URL endpoint of your HTTP-triggered function running locally in terminal.


3. Copy the URL and paste it in a notepad. Append ‘?name=<Your Name>‘ to the URL (replace <Your Name> with your name) and then paste in a browser. It will respond with string like ‘Hello, <Your Name>. This HTTP triggered function executed successfully.‘


In this post, we saw how to create a Python Azure Function using Visual Studio Code and then run it locally using Azure Functions core tools. Read my next post, about How to deploy Azure Function to Azure Cloud from Visual Studio Code.