Share via

Errors in az cli when trying to set/get ContainerApp function keys

Stepan Hlushak 0 Reputation points
2026-03-09T16:42:11.8966667+00:00

Hi,

I have recently started experimentation by deploying the azure function app into the azure container app. I used the following documentation:
https://learn.microsoft.com/en-us/azure/container-apps/functions-usage?pivots=azure-cli

and managed to deploy it successfully. Unfortunately, I can't use my web function as they return that I am not authorized "HTTP Error 401: Unauthorized".

So, I tried to set/list function keys to use them in the x-functions-key header, but got following error:

$ az containerapp function keys list --resource-group $rg --name $func_contapp_name --key-type hostKey

Command group 'containerapp function keys' is in preview and under development. Reference and support levels: https://aka.ms/CLI_refstatus

Connecting...

{

"error": {

"$id": "2",

"code": "UnexpectedException",

"message": "Unexpected exception System.InvalidOperationException: Failed to get or create ephemeral container."

}

}

How can I set/retrieve the function keys from the container app if az cli does not work?

Azure Functions
Azure Functions

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


2 answers

Sort by: Most helpful
  1. Sina Salam 28,281 Reputation points Volunteer Moderator
    2026-03-29T15:23:26.6566667+00:00

    Hello Stepan Hlushak,

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    I understand that you are having errors in az cli when trying to set/get ContainerApp function keys.

    First, ensure the Container App is actively running by forcing at least one replica using

    az containerapp update --name <app> --resource-group <rg> --set template.scale.minReplicas=1
    

    Then confirm an active revision exists with az containerapp revision list -o table, as required in Microsoft Docs: https://learn.microsoft.com/azure/container-apps/scale-app.

    Next, verify the Function host inside the container is fully initialized, since CLI operations depend on it.

    az containerapp logs show --name <app> --resource-group <rg>
    

    Check for “Host started” in logs, aligning with diagnostics guidance: https://learn.microsoft.com/azure/container-apps/logging.

    After that, retrieve the active revision name because multi-revision apps require explicit targeting.

    REVISION=$(az containerapp revision list --name <app> --resource-group <rg> --query "[?properties.active].name" -o tsv)
    

    This ensures the CLI interacts with the correct running revision per revision management docs.

    Then execute the CLI command only after validation steps are satisfied.

    az containerapp function keys list --name <app> --resource-group <rg> --revision $REVISION --key-type hostKeys
    

    If prerequisites are unmet, the command fails due to runtime dependency as documented in Azure CLI references.

    Finally, if the CLI still fails, switch to the REST API which bypasses runtime execution entirely.

    az rest --method POST --url "https://management.azure.com/subscriptions/<sub>/resourceGroups/<rg>/providers/Microsoft.App/containerApps/<app>/functions/admin/host/keys?api-version=2024-03-01"
    

    This direct management-plane call is the most reliable method per Azure REST API guidance: https://learn.microsoft.com/rest/api/resource-manager/.

    I hope this is helpful! Do not hesitate to let me know if you have any other questions or clarifications.


    Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.

    0 comments No comments

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

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.