0

I have an event grid triggered function app. I am using the below code to get function URL.

function Get-Function-Key {
    return (Invoke-AzResourceAction `
            -Action listKeys `
            -ResourceType 'Microsoft.Web/sites/functions/' `
            -ResourceGroupName $ResourceGroup `
            -ResourceName "$FuncAppName/$FuncName" `
            -Force).default
}

$functionKey = Get-Function-Key -FuncAppName $FuncAppName -FuncName $FuncName `
                -ResourceGroup $ResourceGroup

$apiUrl = "https://$FuncAppName.azurewebsites.net/runtime/webhooks/EventGrid?functionName=$FuncName&code=$functionKey"

I noticed the function URL uses masterkey instead of function key. Is there any command in powershell to get master key of the function URL.

4
  • Your function does not have a param block, yet you call it using parameters?? Commented Mar 12, 2021 at 10:30
  • I am new to powershell scripting. I currently exploring , I will change it later as per standards.By the way those parameters are set through azure devops release pipeline. I think we set it at script parameters section in azure powershell task. Commented Mar 12, 2021 at 10:36
  • I have no experience in azure tasks, but if a function should use parameters, you need to define them as the first line in the function: param([string]$FuncAppName, [string]$FuncName, [string]$ResourceGroup) Commented Mar 12, 2021 at 11:06
  • Any update this issue? If it is helpful, please accept it as answer, thanks. Commented Mar 24, 2021 at 8:36

1 Answer 1

2

I test your commands on my side, it returns the function key of the EventGridTrigger in the function app.

So if you want to get the master key, just use the command below.

function Get-Function-Key {
 param([string]$FuncAppName,[string]$ResourceGroup)
    return (Invoke-AzResourceAction `
            -Action listKeys `
            -ResourceType 'Microsoft.Web/sites/host/default' `
            -ResourceGroupName $ResourceGroup `
            -ResourceName "$FuncAppName" `
            -Force).masterKey
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.