How to change function app env variables from logic app workflow

Mazurek, Jakub 40 Reputation points
2024-10-04T07:10:50.14+00:00

Hey,

I need to change env variable as on of the steps that I want automated in logic app workflow but I can't connect to function app in any way or form. How can this be achieved?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,085 questions
Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,201 questions
{count} votes

Accepted answer
  1. Roshan V 80 Reputation points
    2024-10-06T15:19:24.3566667+00:00

    To automate changing an environment variable in your Azure Function App using a Logic App workflow, you can follow a few steps. The issue you're encountering may relate to permission or configuration settings between your Logic App and Function App. Here’s how you can tackle it:

    Steps to Achieve this:

    Use Azure Resource Manager (ARM) API: You can leverage Azure’s ARM REST API to update the environment variables of your Function App. This can be done from within your Logic App workflow using the HTTP action to send a request to the ARM API.

    Steps:

    • Get the Function App’s resource ID.
      • Use an HTTP request to the ARM API to modify the app settings (environment variables) for the Function App.
      Example request:
            http
            Copy code
            PATCH https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.Web/sites/{function-app-name}/config/appsettings?api-version=2021-02-01
      
      In the body, you would include the new environment variable:
            json
            Copy code
            {
      
      Grant Permissions: Make sure your Logic App has the necessary permissions to update the Function App's settings. You can do this by assigning the Contributor or App Configuration Data Owner role to the Logic App in the Function App’s access control (IAM) settings. Use Managed Identity: If you are using Managed Identity for Logic Apps, ensure that it is enabled and has the appropriate permissions on the Function App. You can do this by:
      - Enabling Managed Identity in Logic Apps.
      
         - Assigning the required role to the Logic App's Managed Identity at the Function App level (like `Contributor` or `App Configuration Data Owner`).
      
         **Invoke an Azure Function**: If you can't modify the environment variables directly via ARM, you can consider writing an Azure Function that updates the environment variables, and call this Function from your Logic App. The Function can access and update its own configuration.
      
            - Create an HTTP-triggered Azure Function that updates its environment variables.
      
               - From the Logic App, use the `HTTP` action to call the Function.
      

    Troubleshooting Connection Issues:

    • Authentication: Ensure your Logic App is using appropriate authentication to connect to the Azure Function (Managed Identity, OAuth, or API key).
    • Network Restrictions: Check if the Function App has IP restrictions or VNET integration that may block the Logic App from connecting.
    • API Version: Make sure the API version used in the ARM request matches the latest supported version.

    Let me know if you need further help with specific configurations!To automate changing an environment variable in your Azure Function App using a Logic App workflow, you can follow a few steps. The issue you're encountering may relate to permission or configuration settings between your Logic App and Function App. Here’s how you can tackle it:

    Steps to Achieve this:

    Use Azure Resource Manager (ARM) API: You can leverage Azure’s ARM REST API to update the environment variables of your Function App. This can be done from within your Logic App workflow using the HTTP action to send a request to the ARM API.

    Steps:

    • Get the Function App’s resource ID.
      • Use an HTTP request to the ARM API to modify the app settings (environment variables) for the Function App.
      Example request:
            http
            Copy code
            PATCH https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.Web/sites/{function-app-name}/config/appsettings?api-version=2021-02-01
      
      In the body, you would include the new environment variable:
            json
            Copy code
            {
      
      Grant Permissions: Make sure your Logic App has the necessary permissions to update the Function App's settings. You can do this by assigning the Contributor or App Configuration Data Owner role to the Logic App in the Function App’s access control (IAM) settings. Use Managed Identity: If you are using Managed Identity for Logic Apps, ensure that it is enabled and has the appropriate permissions on the Function App. You can do this by:
      - Enabling Managed Identity in Logic Apps.
      
         - Assigning the required role to the Logic App's Managed Identity at the Function App level (like `Contributor` or `App Configuration Data Owner`).
      
         **Invoke an Azure Function**: If you can't modify the environment variables directly via ARM, you can consider writing an Azure Function that updates the environment variables, and call this Function from your Logic App. The Function can access and update its own configuration.
      
            - Create an HTTP-triggered Azure Function that updates its environment variables.
      
               - From the Logic App, use the `HTTP` action to call the Function.
      

    Troubleshooting Connection Issues:

    • Authentication: Ensure your Logic App is using appropriate authentication to connect to the Azure Function (Managed Identity, OAuth, or API key).
    • Network Restrictions: Check if the Function App has IP restrictions or VNET integration that may block the Logic App from connecting.
    • API Version: Make sure the API version used in the ARM request matches the latest supported version.

    Let me know if you need further help with specific configurations!

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.