Share via

listsecrets API not working in .NET 8.0 Function App

Matthew Dowst 16 Reputation points
2024-10-15T14:39:40.1033333+00:00

I have a Function app that gets deployed via an ARM template. As part of the deployment, it creates an Action Group pointing to one of the HTTP trigger functions in the app. This has worked fine for a year or so now.

I am currently in the process of updating the app from a .NET 6.0 in-process model to a .NET 8.0 isolated worker. After some updates, I was able to get the app working as normal in my local environment and in Azure. However, I am unable to create the Action Group via an ARM template.

When I try to create the Action Group I get the error message:

System.IO.FileNotFoundException: Function (MyFunction) does not exist
   at Kudu.Core.Functions.FunctionManager.GetFuncPathAndCheckExistence(String name)
   at Kudu.Core.Functions.FunctionManager.<GetFunctionSecretsAsync>d__12.MoveNext()

The code for the ARM template (below) shows it is using the listsecrets to get the URL of the function.

{
    "type": "Microsoft.Insights/actionGroups",
    "apiVersion": "2021-09-01",
    "name": "MyFunction-AG",
    "location": "global",
    "tags": {
        "displayName": "MyFunction-AG"
    },
    "properties": {
        "groupShortName": "MyFunctionAG",
        "enabled": true,
        "azureFunctionReceivers": [
        {
            "name": "MyFunction",
            "functionAppResourceId": "[resourceId('Microsoft.Web/sites', parameters('functionAppResource'))]",
            "functionName": "MyFunction",
            "httpTriggerUrl": "[listsecrets(resourceId('Microsoft.Web/sites/functions', parameters('functionAppResource'), 'MyFunction'), '2024-04-01').trigger_url]",
            "useCommonAlertSchema": true
        }
        ]
    }
}

If I run this command via the Invoke-AzRestMethod, I get the same error.

$path = '/subscriptions/mysubscriont/resourceGroups/myrg/providers/Microsoft.Web/sites/MyFunctionApp/functions/MyFunction/listsecrets?api-version=2024-04-01'
$az = Invoke-AzRestMethod -Path $path -Method Post

However, I am able to get this URL just fine through the portal. I can create the Action Group and point it to the function in the portal as well. Even the listkeys API works. It is just the listsecrets that does not work.

To eliminate the possibility of a code issue or something caused by the ARM template, I tested creating a new function app project, with just the built-in HTTP trigger function. I created a brand new app and storage account in Azure and published via Visual Studio.

I confirmed via the PowerShell below that the listsecrets API still does not work. I tested deploying to both East US 2 and South Central US, and received the same error in both.

$path = '/subscriptions/<GUID>/resourceGroups/functionapp8test/providers/Microsoft.Web/sites/FunctionApp120241015141026/functions?api-version=2024-04-01'
$appRest = Invoke-AzRestMethod -Path $path -Method Get
$function = ($appRest.Content | ConvertFrom-Json).value | Where-Object{ $_.name -match 'Function1' }
$function # Returns the function as expected

$funcPath = "$($function.id)?api-version=2024-04-01"
$funcRest = Invoke-AzRestMethod -Path $funcPath -Method Get
$funcRest # Return the details of the function as expected

$funcListPath = "$($function.id)/listsecrets?api-version=2024-04-01"
$listRest = Invoke-AzRestMethod -Path $funcListPath -Method Post
$listRest # Returns System.IO.FileNotFoundException: Function (Function1) does not exist error

Is there something special I need to do to get the listsecrets API working for a .NET 8.0 isolated app?

 

Azure Functions
Azure Functions

An Azure service that provides an event-driven serverless compute platform.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Matthew Dowst 16 Reputation points
    2024-10-15T14:57:25.99+00:00

    I was able to resolve this. I found this GitHub issue with a similar problem. The recommendation was to use the listKeys API. Since this API doesn't give the full URL, I used the string concat and reference function to join the URL and key together in the ARM template. Doing this I was able to create the action group.

    In case anyone else runs into this, I included the updated ARM resource below using the listKeys API.

    {
        "type": "Microsoft.Insights/actionGroups",
        "apiVersion": "2021-09-01",
        "name": "MyFunction-AG",
        "location": "global",
        "tags": {
            "displayName": "MyFunction-AG"
        },
        "properties": {
            "groupShortName": "MyFunctionAG",
            "enabled": true,
            "azureFunctionReceivers": [
            {
                "name": "MyFunction",
                "functionAppResourceId": "[resourceId('Microsoft.Web/sites', parameters('functionAppResource'))]",
                "functionName": "MyFunction",
                "httpTriggerUrl": "[concat(reference(resourceId('Microsoft.Web/sites/functions', parameters('functionAppResource'), 'MyFunction'), '2024-04-01').invoke_url_template, '?code=', listKeys(resourceId('Microsoft.Web/sites/functions', parameters('functionAppResource'), 'MyFunction'), '2024-04-01').default)]",
                "useCommonAlertSchema": true
            }
            ]
        }
    }
    

    Was this answer helpful?

    2 people found this answer helpful.
    0 comments No comments

  2. LeelaRajeshSayana-MSFT 17,871 Reputation points Moderator
    2024-10-15T20:02:23.9+00:00

    Hi @Matthew Dowst Greetings! Welcome to Microsoft Q&A forum. Thank you for posting this question here.

    I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to accept the answer .

    Error Message:

    System.IO.FileNotFoundException: Function (MyFunction) does not exist    at Kudu.Core.Functions.FunctionManager.GetFuncPathAndCheckExistence(String name)    at Kudu.Core.Functions.FunctionManager.<GetFunctionSecretsAsync>d__12.MoveNext()

    Issue:

    Unable to hit the List Function Keys end point after updating the Azure function from .Net 6 in-process model to a .NET 8.0 isolated worker model. This is resulting in failure to create an Azure

    Solution:

    Solution...

    After updating the model, old API end point cannot be used. Please use the new List Function Keys API end point. Use the following template to create an Action group for the Azure function sing ARM deployment

    "azureFunctionReceivers": [
            {
                "name": "MyFunction",
                "functionAppResourceId": "[resourceId('Microsoft.Web/sites', parameters('functionAppResource'))]",
                "functionName": "MyFunction",
                "httpTriggerUrl": "[concat(reference(resourceId('Microsoft.Web/sites/functions', parameters('functionAppResource'), 'MyFunction'), '2024-04-01').invoke_url_template, '?code=', listKeys(resourceId('Microsoft.Web/sites/functions', parameters('functionAppResource'), 'MyFunction'), '2024-04-01').default)]",
                "useCommonAlertSchema": true
            }
    

    If you have any other questions, please let me know. Thank you again for your time and patience throughout this issue.

    Was this answer helpful?

    0 comments No comments

Your answer

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