How to Read value from App Configuration in Logic App

Posted On February 9, 2021 by Yogesh Gore Posted in 

Azure App Configuration is a managed service that helps developers centralize their application configuration and feature settings simply and securely. Use Azure App Configuration to store and secure configuration settings for your application in a single location. App configuration offer the following benefits.

  • A fully managed service that can be set up in minutes
  • Flexible key representations and mappings
  • Tagging with labels
  • Point-in-time replay of settings
  • Dedicated UI for feature flag management
  • App configuration is useful in following Scenario.
  • Centralize management and distribution of hierarchical configuration data for different environments and geographies
  • Dynamically change application settings without the need to redeploy or restart an application
  • Control feature availability in real-time
  • The only problem was that unlike Key Vault, which has an available connector to be used inside Logic Apps, App Configuration doesn’t have a connector available. So in order to implement this scenario we’ll going to use Azure function app

Create an Azure Function App:

The Azure Functions project template in Visual Studio creates a project that you can publish to a function app in Azure.

  1. From the Visual Studio menu, select File > New > Project.
  2. In Create a new project, enter functions in the search box, choose the Azure Functions template, and then select Next.
  3. In Configure your new project, enter a Project name for your project, and then select Create. The function app name must be valid as a C# namespace, so don’t use underscores, hyphens, or any other nonalphanumeric characters.
  4. Select Httptrigger function app

Connect to App configuration store:

  1. Right-click your project, and select Manage NuGet Packages. On the Browse tab, search for and add the Microsoft.Extensions.Configuration.AzureAppConfiguration NuGet package to your project.
  2. Add the following namespaces of the .NET Core configuration and the App Configuration provider.

using Microsoft.Extensions.Configuration;

using Microsoft.Extensions.Configuration.AzureAppConfiguration;

  • The key that we want to read should be passed by query parameter.
    • string appKey = req.Query[“appKey”];
  • And finally, the function should raise proper HTTP response status codes according to the situation:
  • 200 Ok if successful returns a value for that key
  • 500 Internal Server Error if something fails, for example, there is no connection string to the App Configuration defined
  • and 404 Not Found if the key is not found
  • Use below code for reference

if(string.IsNullOrEmpty(appKey))

                return new BadRequestObjectResult(“parameter ‘appKey’ not found or empty.”);

            try

            {

                string connectionString = Environment.GetEnvironmentVariable(“AppConfigConnection”);

                var builder = new ConfigurationBuilder();

                builder.AddAzureAppConfiguration(connectionString);

                var build = builder.Build();

                string keyValue = build[appKey.ToString()];

                if (string.IsNullOrEmpty(keyValue))

                {

                    var result = new ObjectResult(“Azure Configuration Key not found – ” + appKey);

                    result.StatusCode = StatusCodes.Status404NotFound;

                    return result;

                }

                else return new OkObjectResult(keyValue);

            }

            catch(Exception ex)

            {

                var result = new ObjectResult(ex.Message);

                result.StatusCode = StatusCodes.Status500InternalServerError;

                return result;

            }

  • Once you create your Function App and all you key-values inside App Configuration, you have to:
  • Go to your Function App Configuration option under Settings 
  • And create a new application settings call AppConfigConnection containing the connection string to your App Configuration resource.
  • Once we done that you can call Azure Function in your logic app

Share Story :

SEARCH BLOGS :

FOLLOW CLOUDFRONTS BLOG :


Secured By miniOrange