5

I have a bicep template that creates a function app in a dedicated module. I would like out the function app key from the module. Anyone know how I can get the function key?

I can't find it in the list of properties:

enter image description here

Thomas
  • 24,234
  • 6
  • 81
  • 125
Rob Bowman
  • 7,632
  • 22
  • 93
  • 200

1 Answers1

12

If you would like to retrieve the default host key, you can use the listkeys function:

param functionAppName string

resource functionApp 'Microsoft.Web/sites@2022-09-01' existing = {
  name: functionAppName
}

resource functionAppHost 'Microsoft.Web/sites/host@2022-09-01' existing = {
  name: 'default'
  parent: functionApp
}

// Default host key
output defaultHostKey string = functionAppHost.listKeys().functionKeys.default

// Master key
output masterKey string = functionAppHost.listKeys().masterKey

// Addtionally grab the system keys
output systemKeys object = functionAppHost.listKeys().systemKeys
Thomas
  • 24,234
  • 6
  • 81
  • 125
  • 1
    Does not work for me (anymore), I get the error `No route registered for '/api/functions/MyFunctionName/host/default/listkeys?api-version=2016-08-01'` – Heinrich Ulbricht May 12 '22 at 15:22
  • 3
    @HeinrichUlbricht You need to deploy your code to the Function App, before `/api/functions/MyFunctionName` is created. The functions inside the Function App are created by the code. Therefore I recommend getting the host key using Azure CLI: 1. Deploy Function App 2. Deploy code 3. Get host key – Michael Jul 14 '22 at 07:10
  • The solution is great but a different approach needed if the function app is created in a module rather than directly in the "main" bicep template: https://stackoverflow.com/questions/76463916/get-function-app-default-host-key-when-created-in-bicep-module – Rob Bowman Jun 13 '23 at 10:24