Centralize Configuration for Azure Functions with Azure App Configuration
  • 24 Mar 2023
  • 2 Minutes to read
  • Dark
  • PDF

Centralize Configuration for Azure Functions with Azure App Configuration

  • Dark
  • PDF

#ServerlessTips - Azure Functions
Author: Rahul Rai Microsoft MVP

Azure Functions support referencing configuration key-values from the Azure App Configuration service. You can manage configuration key-values across resources and deployment environments using App Configuration. The integration between App Configuration and Azure Functions enables you to specify the application settings or connection strings as key-value pairs in an Azure App Configuration store instead of as direct values within Azure Functions. The function app can use its managed identity to resolve the value from the store and expose it as an environment variable that your application can reference.

You can learn more about the feature and its limitation in the feature documentation on the Microsoft documentation website.


  1. Use the App Configuration quickstart guide to create a new App Configuration store.

  2. Create a new key-value configuration named myKey and myValue in the store.

MicrosoftTeams-image 51

Figure 1: Add a configuration key-value pair

  1. Use the Azure Functions quickstart guide to create a new one. NET-based Azure Function that uses C# script and in-portal editing.

  2. Generate a managed identity for your Azure Function by clicking on Identity and setting the Status toggle to On.

MicrosoftTeams-image 52

Figure 2: Create a managed identity for the function

  1. Enable the function to access the Azure App Configuration store by following these steps. a. Click on Access Control and then on the Add role assignment button.

MicrosoftTeams-image 531

Figure 3: Add role assignment

b. Select the App Configuration Data Reader role in the next window and click on Next.

MicrosoftTeams-image 54

Figure 4: Select the App Configuration Data Reader role

c. Choose Managed Identity as the Member you would like to grant access to. Next, select the Function App you created from the list of available managed identities. Confirm your choice by clicking on Select and then clicking Next to move to the final step of the wizard.

MicrosoftTeams-image 552

Figure 5: Assigning role to the function app

d. Click on the Review+assign button to finish the assignment process. Your function can now access the App Configuration store.

  1. Create a new configuration in your Function App named myKey (the name can be different) and set the value as @Microsoft.AppConfiguration(Endpoint=https://.azconfig.io; Key=myKey).

MicrosoftTeams-image 561

Figure 6: New key referencing a key from Azure App Configuration store

  1. In your function, you can fetch this value as an environment variable as follows:
#r "Newtonsoft.Json" 
using System.Net; 
using Microsoft.AspNetCore.Mvc; 
using Microsoft.Extensions.Primitives; 
using Newtonsoft.Json; 
public static async Task<IActionResult> Run(HttpRequest req, ILogger log) 
    string responseMessage = $"Value from App Configuration: {System.Environment.GetEnvironmentVariable("myKey")}"; 
    return new OkObjectResult(responseMessage); 
  1. Send an HTTP request from the inbuilt code+test console to execute the function. An example of the output received from the function can be seen in the screenshot below.

MicrosoftTeams-image 571

Figure 7: Response from the function

Was this article helpful?