Way to get Azure Function default key with ARM output or powershell

Question:

I’m attempting to set up integration testing for an Azure Function app. Deployment is going fine, but I need a way to programatically get the default key to run my integration tests.

I’ve tried what is linked here – Get Function & Host Keys of Azure Function In Powershell – but cannot get the listsecrets working in my ARM deployment template. Listsecrets is not recognized.

Does anyone know how to get this key with an ARM template and/or powershell?

Answer:

After updates to Microsoft’s ARM APIs it is now possible to retrieve Azure Function keys directly from the ARM deployment outputs.

Example

Outputs

The Outputs property will contain a Newtonsoft.Json.Linq.JObject entry that contains all of the keys for the Azure Function i.e., master, system keys, and function keys (which includes the default key). Unfortunately, the JObject combined with the deployment variable type is a bit tortuous to get into and you should be warned, is case sensitive. (If you’re working in PowerShell it can be massaged into hashtables for consumption. See Bonus below.)

Bonus

The code below gets rid of the extra .Value calls.

Source:

Way to get Azure Function default key with ARM output or powershell by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply