azure-functions-host: ARM deployment fails when using WEBSITE_RUN_FROM_PACKAGE and listkey function

I have an Azure ARM template that deploys two Azure Functions to an Azure App Service Premium Plan (EP1). The templates add the default host key of the first function to the app settings of the first function using the listkey function:

"FunctionOneKey": "[listkeys(concat(variables('functionOneppId'), '/host/default/'),'2016-08-01').functionKeys.default]"

If I deploy this template to a new resource group, it works the first time (at least most of the time). Every subsequent deployment fails with a Bad Request Error:

{
    "Code": "BadRequest",
    "Message": "Encountered an error (ServiceUnavailable) from host runtime.",
    "Target": null,
    "Details": [
        {
            "Message": "Encountered an error (ServiceUnavailable) from host runtime."
        },
        {
            "Code": "BadRequest"
        },
        {
            "ErrorEntity": {
                "Code": "BadRequest",
                "Message": "Encountered an error (ServiceUnavailable) from host runtime."
            }
        }
    ],
    "Innererror": null
}

The reason for the ServiceUnavailable error is probably because Kudu adds a web.config with a rewrite rule (because I use WEBSITE_RUN_FROM_PACKAGE but don’t have deployed the function).

Investigative information

Please provide the following:

  • Function App version: 3.0 / 2.0
  • Region: Tested with North Europe, Germany West Central

Repro steps

The templates is available here.

You can reproduce this issue by deploying this template at least two times:

New-AzResourceGroupDeployment -ResourceGroupName 'my-resource-group' -TemplateFile "c:\Path\to\azuredeploy.json" -name "azuredeploy-$(New-Guid)"

Expected behavior

I should be able to run the ARM deployment multiple times without an error.

Known workarounds

The deployment works if I disable WEBSITE_RUN_FROM_PACKAGE.

Related information

I posted a related question on StackOverflow.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 31 (11 by maintainers)

Most upvoted comments

Same issue here, I cannot use listkeys, and I get the same error message, which really does not say anything meaning- or helpful.

My template is deploying an EventGrid Topic and some EventTopic Subscribers, I only reference the Function App to get the key, in order to use it for the Subscribers. The Function App, however is Run From package, since C# code is deployed to it in an earlier stage.

@ alI am closing this thread since there are too many different issues being conflated and it is very difficult to see what needs to be investigated / what is failing.

Please open a new (separate) issue and feel free to @ me and I will follow up individually.

I opened a case with support this week on a similar issue. I was trying to use a Linux based function app, however the container wouldn’t spin up before the “create” of the function app was done so it would fail. Moving to a Windows function app this problem does not seem to exist.

I did experience failures consistently when using a consumption plan. Normal app service plan worked fairly reliably.

Also, I had a similar issue with listKeys on a function app slot, but this was because I was missing a dependency on the creation of the slot. Even if you aren’t using a slot, double/triple check your dependencies. I actually used a dependency on the config/appsettings resource of the function app which so far has been working reliably.

I have exactly the same issue but I use neither App Service Premium Plan nor WEBSITE_RUN_FROM_PACKAGE. In my case it is key vault references which seem to trigger this error. I updated template to use key vault references and get this error. If I deploy previous version of the template - it works fine. If I delete app service - both versions of the template work fine.

It is reproducible 100% of the time for me.

Also, I don’t know if this is relevant but I’m using implicit consumption hosting plan:

A hosting plan is only required when you choose to run your function app on a Premium plan (in preview) or on an App Service plan.