If a Logic App needs to start an Azure Function that runs longer than an HTTP call can wait, every option is a bit of a pain to implement. This post will discuss some of those options and a new way I did it in a recent proof of concept.

The problem

The scenario is common. A Logic App orchestrates a daily process, and one step is heavy work that lives in an Azure Function: a big data sync, a report build, a bulk clean-up. It takes 20 minutes, maybe longer.

The obvious design is for the Logic App to call an HTTP-triggered function and wait. That doesn’t work. The Logic App’s HTTP action gives up long before a 20-minute job finishes. Separately, an HTTP-triggered function has to respond within 230 seconds whatever its timeout is set to, because that’s the limit of the Azure load balancer in front of it.

So you have to decouple starting the work from doing the work. That’s where the workarounds come in.

The usual workarounds, and why they hurt

ApproachHow it worksWhat hurts
Service Bus triggerThe Logic App drops a message on a queue, and a queue-triggered function does the workAn extra resource to deploy and secure. The trigger polls the queue around the clock for a job that runs once a day. Poison messages and visibility timeouts need thought
Event Grid triggerThe Logic App publishes an event to a custom topic, and an Event Grid-triggered function does the workPush rather than poll, but still a topic and a subscription to deploy, secure and monitor for a single call
Return 202, work on a background threadAn HTTP function replies straight away and carries on with Task.Run or similarNot a supported pattern. The host doesn’t know the work exists, so it can be cut off on scale-in, restart or deployment, with no retries and no clear record of failure
Durable FunctionsAn HTTP starter returns 202 with a status URL, and the Logic App’s HTTP action polls it automaticallyThe “proper” answer, but it brings a whole programming model (orchestrator rules, task hub storage) to run one long method

All of these work. None of them feels proportionate for “run this method once a day when the Logic App says so”. It’s always needed a workaround, so the real question is which one is least bad.

Where the idea came from

Recently I ran a timer-triggered function by hand with the portal’s Test/Run button. Under the covers, it looked like nothing more than an HTTP POST. That raised two questions:

  1. Could a Logic App make the same call?
  2. If it could, would a timer function that never fires on its own be the on-demand, long-running job I’d been working around for years?

The answer to both is yes, and it avoids the main problem with each workaround above:

  • No HTTP timeout. The call returns 202 straight away, and the function then runs as a normal, host-managed execution. It isn’t tied to the HTTP request, so the 230-second limit doesn’t apply.
  • No extra resources. There’s no queue, topic or subscription, and nothing polling.
  • No background-thread hack. The host knows about the execution, logs it as a normal invocation in Application Insights, and applies the function timeout as usual.
  • No new programming model. It’s an ordinary timer function.

How the portal does it

The portal’s Test/Run button calls the Functions host’s admin endpoint, which can run any function whatever its trigger:

POST https://<function-app>.azurewebsites.net/admin/functions/<FunctionName>
x-functions-key: <master key>
Content-Type: application/json

{ "input": "" }

A successful call returns 202 Accepted, and the function runs asynchronously.

The important detail is the key. Endpoints under /admin/ accept only the master key (_master). Function keys and the default host key are rejected. The master key gives administrative access to the whole Function App, so it isn’t something you want to paste into a workflow. Microsoft’s own docs warn against sharing or distributing it (Work with access keys).

Step 1: Call the admin endpoint from a Logic App

A Logic App can make the same request with a standard HTTP action:

SettingValue
MethodPOST
URIhttps://<function-app>.azurewebsites.net/admin/functions/MyTimerFunction
Headerx-functions-key: the master key
HeaderContent-Type: application/json
Body{ "input": "" }

That’s enough to prove the idea works. Keep three things in mind:

  • It’s fire-and-forget. The 202 means the run was accepted, not that it succeeded. If the Logic App needs to know the result, have the function write its outcome somewhere the Logic App can check, such as a table row, a blob or a callback. If you need a status endpoint you can poll, that’s the point where Durable Functions starts to earn its keep.
  • The function timeout still applies. The run isn’t limited by HTTP, but it is limited by functionTimeout in host.json. On the Consumption plan the maximum is 10 minutes. Flex Consumption, Premium and Dedicated plans allow much longer runs, so check your plan before relying on this for a 30-minute job.
  • Networking. If the Function App has access restrictions or a private endpoint, the Logic App must be able to reach it. That usually means Logic Apps Standard with VNet integration.
  • The key. Hard-coding the master key in the workflow is the weak spot. Step 3 removes it.

Step 2: Give it a schedule that never fires

To make the function on-demand only, keep it enabled but give it a date that doesn’t exist. Azure Functions uses six-field NCRONTAB expressions (second minute hour day month day-of-week), so this means midnight on 31 February:

0 0 0 31 2 *

Put the schedule in an app setting rather than in code. Then you can switch a real schedule back on without redeploying:

using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;

public class MyTimerFunction
{
    private readonly ILogger<MyTimerFunction> _logger;

    public MyTimerFunction(ILogger<MyTimerFunction> logger) => _logger = logger;

    // Schedule comes from the MyTimerSchedule app setting.
    // "0 0 0 31 2 *" (31 February) means it only runs when triggered manually.
    [Function("MyTimerFunction")]
    public void Run([TimerTrigger("%MyTimerSchedule%", RunOnStartup = false)] TimerInfo timer)
    {
        _logger.LogInformation("MyTimerFunction ran at {time}", DateTime.UtcNow);
    }
}

Then add the app setting MyTimerSchedule = 0 0 0 31 2 * (or put it in local.settings.json for local runs).

Two details matter:

  • RunOnStartup must stay false. It’s false by default, but if it’s true the function runs every time the app starts or scales out, whatever the schedule says. Setting it explicitly documents the intent.
  • Leave a comment. An impossible date looks like a bug to the next person who reads the code. Also check the startup logs after deploying, which list the next scheduled occurrences, to confirm the runtime is happy with it.

Step 3: Remove the stored key with a managed identity

The admin endpoint doesn’t accept Microsoft Entra ID tokens, so a managed identity can’t call it directly. What it can do is ask Azure Resource Manager for the master key at runtime. That way the key is never stored in the workflow, Key Vault or anywhere else.

  1. Turn on the Logic App’s system-assigned managed identity.
  2. Give that identity Website Contributor on the Function App. Any role that includes Microsoft.Web/sites/host/listkeys/action will do.
  3. Add an HTTP action named Get_keys:
    • Method: POST
    • URI: https://management.azure.com/subscriptions/<sub-id>/resourceGroups/<rg>/providers/Microsoft.Web/sites/<function-app>/host/default/listKeys?api-version=2022-03-01
    • Authentication: Managed identity (system-assigned), audience https://management.azure.com/
  4. Add a second HTTP action that calls the admin endpoint as in Step 1, with the header set to x-functions-key: @{body('Get_keys')?['masterKey']}.
  5. Turn on Secure outputs for Get_keys and Secure inputs for the second action, so the key never shows in run history.

The trade-off is worth being honest about. You’ve swapped a stored secret for a role assignment, and Website Contributor can do much more than read keys. Scope the assignment to that single Function App, not the resource group. If least privilege matters a lot to you, a custom role with only the listkeys action is tighter still.

So which is the least-worst workaround?

ApproachExtra Azure resourcesSupported patternLogic App gets the resultMain cost
Queue triggerStorage queueYesNoAlways-on polling for a daily job
Event Grid triggerTopic + subscriptionYesNoMore infrastructure for one call
202 + background threadNoneNoNoWork can be silently killed
Durable FunctionsTask hub storageYesYes, via pollingA new programming model
On-demand timer via admin APINoneYes (same call the portal makes)NoNeeds the master key, or a managed identity that can read it

If the Logic App only needs to start the job, the on-demand timer is the least-worst option I’ve found. It needs no new resources, doesn’t poll, it is kind of a hack, but the code is an ordinary function. The KISS principle applies very well in situations like this.

If the Logic App needs to wait for the result and branch on it, use Durable Functions. Its async HTTP pattern is built for that, and Logic Apps follows the 202 and status URL natively.

The one thing to be careful with is the master key. Use the managed identity approach in Step 3, scope the role to the single Function App, and turn on secure inputs and outputs.

 

Buy Me A Coffee