Azure Functions returns InternalServerError from the host runtime
Fix it fast
Most common cause, 1 of 3AzureWebJobsStorage is missing, wrong or points at a deleted account
Put a current connection string back into AzureWebJobsStorage, then restart.
conn=$(az storage account show-connection-string --name mystorageacct --resource-group my-rg --query connectionString -o tsv)
az functionapp config appsettings set --name my-func-app --resource-group my-rg --settings AzureWebJobsStorage="$conn"
az functionapp restart --name my-func-app --resource-group my-rgShort answer
Encountered an error (InternalServerError) from host runtime shows up when the Functions host behind the app is not running, so listKeys, deployments and portal calls fail. On runtime 4.x Microsoft names lost storage access as the usual reason: a missing or stale AzureWebJobsStorage, a storage firewall or Shared Key block, or ten unreadable host.snapshot backups. Fix storage, then restart.
Which cause do you have?
List the app settings and look for AzureWebJobsStorage. Missing or empty points to cause 1; a value that looks right sends you to the storage account itself (cause 2) and then to its secrets container (cause 3).
az functionapp config appsettings list --name my-func-app --resource-group my-rg --query "[?name=='AzureWebJobsStorage']"Then find the line you see in this list and open its fix:
- 1AzureWebJobsStorage is missing, wrong or points at a deleted account
The query returns an empty list, or the account named in the connection string no longer exists or had its keys rotated - 2The storage account refuses the app: firewall rules or Shared Key turned off
The connection string is valid, but the account's network default action is Deny or allowSharedKeyAccess is false - 3Ten unreadable host.snapshot key backups block the secrets repository
Diagnose and solve problems shows AZFD0007, or the azure-webjobs-secrets container holds a pile of host.snapshot.<date>.json files for this app
What does the error look like?
Encountered an error (InternalServerError) from host runtime.Error: Azure Functions Runtime is unreachable. Click here for details on storage configuration.AZFD0007: Repository has more than 10 nondecryptable secrets backups
Cause 1 of 3
AzureWebJobsStorage is missing, wrong or points at a deleted account
You seeThe query returns an empty list, or the account named in the connection string no longer exists or had its keys rotated
Check
Microsoft's troubleshooting page says the Functions runtime cannot start once the app loses its storage account, and reports in Azure-Functions issue 1657 cleared after AzureWebJobsStorage was set again. Deployment slots and Resource Manager scripts are the usual way the setting gets deleted or overwritten. Regenerated storage keys leave an old string behind, and on Consumption or Elastic Premium plans WEBSITE_CONTENTAZUREFILECONNECTIONSTRING needs the same care.
az storage account show-connection-string --name mystorageacct --resource-group my-rgFix
Put a current connection string back into AzureWebJobsStorage, then restart. If the account was deleted, create a new one, set the string and redeploy your code, since the old package is gone with it.
conn=$(az storage account show-connection-string --name mystorageacct --resource-group my-rg --query connectionString -o tsv)
az functionapp config appsettings set --name my-func-app --resource-group my-rg --settings AzureWebJobsStorage="$conn"
az functionapp restart --name my-func-app --resource-group my-rgVerify
The portal lists your functions again, and the listKeys step in the template completes.
az functionapp keys list --name my-func-app --resource-group my-rgConfirmed by learn.microsoft.com
Cause 2 of 3
The storage account refuses the app: firewall rules or Shared Key turned off
You seeThe connection string is valid, but the account's network default action is Deny or allowSharedKeyAccess is false
Check
Microsoft lists a storage firewall that does not admit the function app, an App Service Environment without the right network rules, and Shared Key authorization switched off as reasons the host loses its storage. A key-based connection string cannot work while Shared Key is disabled.
az storage account show --name mystorageacct --resource-group my-rg --query "{sharedKey:allowSharedKeyAccess, network:networkRuleSet.defaultAction}"Fix
Allow the function app's traffic through the storage firewall (or its virtual network), and switch Shared Key back on while the app still authenticates with a key.
az storage account update --name mystorageacct --resource-group my-rg --allow-shared-key-access true
az functionapp restart --name my-func-app --resource-group my-rgVerify
sharedKey prints true or null (both permit Shared Key), and the host answers the keys request without the 500 error.
az functionapp keys list --name my-func-app --resource-group my-rgConfirmed by learn.microsoft.com
Cause 3 of 3
Ten unreadable host.snapshot key backups block the secrets repository
You seeDiagnose and solve problems shows AZFD0007, or the azure-webjobs-secrets container holds a pile of host.snapshot.<date>.json files for this app
Check
The host keeps its access keys in an encrypted file in the azure-webjobs-secrets container. Each time it cannot decrypt that file it writes a host.snapshot backup and starts fresh; at ten backups it gives up and the app may not start. Recreating an app with the same name on the same storage account, a changed decryption key and lifecycle policies all lead here.
az storage blob list --account-name mystorageacct --container-name azure-webjobs-secrets --prefix my-func-app/ --query "[].name" -o tsv --auth-mode loginFix
Delete the snapshot backups for this app only, then restart so the host has room to regenerate its key file. Since the old file could not be decrypted, read the keys again afterwards and update any caller that stored them.
az storage blob delete-batch --account-name mystorageacct --source azure-webjobs-secrets --pattern "my-func-app/host.snapshot.*" --auth-mode login
az functionapp restart --name my-func-app --resource-group my-rgVerify
The snapshot list is empty or short, AZFD0007 no longer appears, and the keys request succeeds.
az functionapp keys list --name my-func-app --resource-group my-rgConfirmed by learn.microsoft.com
How do I stop it coming back?
- Give each function app its own storage account, or at least never reuse an app name on a shared account.
- Never tick slot setting on AzureWebJobsStorage, and include it in every template that creates the app, since the host needs it valid from creation.
- Before enabling the storage firewall or disabling Shared Key on an account, list every function app whose AzureWebJobsStorage points at it.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: Raheeb.