Skip to content
kendaleiv.com
Go back

Running Code On Local Computer / Localhost Only Using Azure Functions With C#

Azure Functions is a serverless hosting offering available in Microsoft Azure. While authoring code you may find a need to run code only during local development.

Azure Functions provides an AZURE_FUNCTIONS_ENVIRONMENT environment variable that can help! (Note: Per the documentation it seems to be a version 2.x and later feature, I couldn’t find a reference to it in https://github.com/Azure/azure-functions-host/tree/v1.x)

var isLocal = Environment
    .GetEnvironmentVariable("AZURE_FUNCTIONS_ENVIRONMENT")
    ?.Equals("development", StringComparison.OrdinalIgnoreCase) == true;

This is particularly useful over the #if DEBUG preprocessor directive if you want the code to run the same as local when running on a build agent in a Release configuration.

Hope that helps!


Share this post:

Previous Post
Thoughts On Debugging Durable Functions Extension Orchestrations For Azure Functions Backed By Azure Table Storage
Next Post
Debugging Fan-Out Operation Failures With Custom Exception Messages Using Durable Functions Extension For Azure Functions On C#