Azure Functions Documentation

Run Azure Functions Locally

Developing Azure Functions locally is a crucial part of the development workflow. The Azure Functions Core Tools provide a local development environment that mimics the behavior of Azure Functions in the cloud. This allows you to test, debug, and iterate on your functions without deploying to Azure.

Prerequisites

Before you can run Azure Functions locally, ensure you have the following installed:

Starting the Local Runtime

Once your project is set up, you can start the local Functions host using the Core Tools. Navigate to your project's root directory in your terminal or command prompt and run the following command:

func start

This command will:

Testing Functions Locally

After running func start, your functions will be available at specific local URLs. For HTTP-triggered functions, you'll typically see output similar to this:

Functions:

        MyHttpTrigger: [GET,POST] http://localhost:7071/api/MyHttpTrigger

You can then test these endpoints using tools like:

Note: The default port for the local Functions host is 7071, but this can be configured.

Debugging Functions

Debugging is a critical part of local development. The Azure Functions Core Tools integrate with popular debuggers for various languages.

Debugging with Visual Studio Code

If you are using VS Code with the Azure Functions extension:

  1. Open your Functions project in VS Code.
  2. Ensure you have the correct launch configuration in your launch.json file (usually created by the extension).
  3. Set breakpoints in your function code.
  4. Press F5 or go to the "Run and Debug" view and select your Azure Functions launch configuration, then click the play button.

The debugger will attach to the Functions host, and execution will pause at your breakpoints, allowing you to inspect variables, step through code, and analyze the execution flow.

Debugging with other IDEs/.NET

For .NET development, you can attach a debugger (like the one in Visual Studio) to the running Functions host process. The Core Tools typically run as a .NET process.

Local Settings

You can configure local settings for your functions, such as connection strings or application settings, using the local.settings.json file. This file is not deployed to Azure and is used only for local development.

{
              "IsEncrypted": false,
              "Values": {
                "AzureWebJobsStorage": "UseDevelopmentStorage=true",
                "FUNCTIONS_WORKER_RUNTIME": "dotnet",
                "MyCustomSetting": "local_value"
              }
            }

The values in this file are loaded into the environment variables accessible by your functions.

Tip: For local Azure Storage emulation, set AzureWebJobsStorage to UseDevelopmentStorage=true. The Azure Storage Emulator is included with Visual Studio or can be installed separately.

Running Different Function Types Locally

The func start command works for most function types, including:

Important: While the local runtime closely mimics Azure Functions, there might be subtle differences, especially with complex integrations or resource-specific behaviors. Always test your functions in a deployed Azure environment before going to production.