Tutorial: Create and deploy serverless Azure Functions in Python with Visual Studio Code

In this article, you use Visual Studio Code and the Azure Functions extension to create a serverless HTTP endpoint with Python and to also add a connection (or "binding") to storage.

Azure Functions runs your code in a serverless environment without needing to provision a virtual machine or publish a web app. The Azure Functions extension for Visual Studio Code greatly simplifies the process of using Functions by automatically handling many configuration concerns.

If you encounter issues with any of the steps in this tutorial, we'd love to hear the details. Use the I ran into an issue button at the end of each article to submit feedback.

Prerequisites

Azure subscription

If you don't have an Azure subscription, sign up now for a free 30-day account with $200 in Azure credits to try out any combination of services.

Visual Studio Code, Python, and the Azure Functions extension

Install the following software:

Note

The Azure Functions extension is included with the the Azure Tools extension pack.

Azure Functions Core Tools

Follow the instructions for your operating system on Work with Azure Functions Core Tools. The tools themselves are written in .NET Core, and the Core Tools package is best installed using the Node.js package manager, npm, which is why you need to install .NET Core and Node.js at present, even for Python code. You can, however bypass the .NET Core requirement using "extension bundles" as described in the aforementioned documentation. Whatever the case, you need install these components only once, after which Visual Studio Code automatically prompts you to install any updates.

Sign in to Azure

Once you've installed the Azure extension, sign into your Azure account by navigating to the Azure explorer, select Sign in to Azure, and follow the prompts. (If you have multiple Azure extensions installed, select the one for the area in which you're working, such as App Service, Functions, etc.)

Sign in to Azure through VS Code

After signing in, verify that the email address of your Azure account (or "Signed In") appears in the Status Bar and your subscription(s) appears in the Azure explorer:

Visual Studio Code status bar showing Azure account

Visual Studio Code Azure App Service explorer showing subscriptions

Note

If you see the error "Cannot find subscription with name [subscription ID]", this may be because you are behind a proxy and unable to reach the Azure API. Configure HTTP_PROXY and HTTPS_PROXY environment variables with your proxy information in your terminal:

# macOS/Linux
export HTTPS_PROXY=https://username:password@proxy:8080
export HTTP_PROXY=http://username:password@proxy:8080

# Windows
set HTTPS_PROXY=https://username:password@proxy:8080
set HTTP_PROXY=http://username:password@proxy:8080

Verify prerequisites

To verify that all the Azure Functions tools are installed, open the Visual Studio Code Command Palette (F1), select the Terminal: Create New Integrated Terminal command, and once the terminal opens, run the command func:

Check Azure Functions core tools prerequisites

The output that starts with the Azure Functions logo (you need to scroll the output upwards) indicates that the Azure Functions Core Tools are present.

If the func command isn't recognized, then verify that the folder where you installed the Azure Functions Core Tools is included in your PATH environment variable.

I ran into an issue