[英]Get list of actual Azure Function endpoints from Powershell
I'm trying to get a full list of function endpoints in my Azure function app from a Powershell script.我正在尝试从 Powershell 脚本获取 Azure 函数应用程序中函数端点的完整列表。 I can get the list of functions from the management.azure.com API, but it just has the function name, like...我可以从 management.azure.com API 获取函数列表,但它只有函数名称,例如...
/subscriptions/ea4a3766-c3a8-4b9c-xxxx-xxxxxxxxxxxx/resourceGroups/MyResourceGroup/providers/Microsoft.Web/sites/MyFunctionAppName/functions/FunctionName
But the function actually has an endpoint of (for instance) http://myfunctionapp.azurewebsites.net/api/allsources/{sourceName}
但该函数实际上有一个端点(例如) http://myfunctionapp.azurewebsites.net/api/allsources/{sourceName}
How can I get that endpoint name from the Azure management API from Powershell?如何从 Powershell 的 Azure 管理 API 获取该端点名称? It's displayed in the "Get Function URL" button on the portal, so I would imagine it has to be there somewhere.它显示在门户上的“获取函数 URL”按钮中,所以我想它必须在某个地方。
EDIT: The suggested duplicate still doesn't provide the actual function endpoint.编辑:建议的副本仍然没有提供实际的函数端点。 For instance, I have a function called CheckLock.例如,我有一个名为 CheckLock 的函数。 Its endpoint per the "Get Function URL" button on the portal (and the one that I want) is: https://myfunctionapp.azurewebsites.net/api/account/lock/{id}?code=myfunctioncode
门户上的“获取函数 URL”按钮(以及我想要的那个)的端点是: https://myfunctionapp.azurewebsites.net/api/account/lock/{id}?code=myfunctioncode
: https://myfunctionapp.azurewebsites.net/api/account/lock/{id}?code=myfunctioncode
{id} https://myfunctionapp.azurewebsites.net/api/account/lock/{id}?code=myfunctioncode
What I'm getting from the suggested duplicate is:我从建议的副本中得到的是:
@{
name=CheckLock;
function_app_id=/subscriptions/ea4a3766-c3a8-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myresourcegroup/providers/Microsoft.Web/sites/myfunctionappname;
script_root_path_href=https://myfunctionappname.scm.azurewebsites.net/api/vfs/site/wwwroot/CheckLock/;
script_href=https://myfunctionappname.scm.azurewebsites.net/api/vfs/site/wwwroot/bin/Funcs.dll;
config_href=https://myfunctionappname.scm.azurewebsites.net/api/vfs/site/wwwroot/CheckLock/function.json;
secrets_file_href=https://myfunctionappname.scm.azurewebsites.net/api/vfs/data/functions/secrets/CheckLock.json;
href=https://myfunctionappname.scm.azurewebsites.net/api/functions/CheckLock;
config=;
files=;
test_data=
}
AZ PowerShell has introduced the Invoke-AzResourceAction
cmdlet. AZ PowerShell 引入了Invoke-AzResourceAction
cmdlet。 This does exactly what it says on the tin - it allows you to invoke an action against an Azure Resource.这正是它在罐头上所说的 - 它允许您调用针对 Azure 资源的操作。
It's possible to get a Function Key and URL through the listkeys
action as follows -可以通过listkeys
操作获取功能键和 URL,如下所示 -
$functionApp = Get-AzWebAppSlot -Name $FunctionAppName -ResourceGroup $ResourceGroupName -Slot $Slot
$functionSecrets = Invoke-AzResourceAction -ResourceId ("{0}/functions/{1}" -f $functionApp.Id, $FunctionName) -Action "listkeys" -ApiVersion "2019-08-01" -Force
The variable $functionSecrets
now contains two properties -变量$functionSecrets
现在包含两个属性 -
key
: The default function-level key (will only work for $FunctionName
). key
:默认的函数级键(仅适用于$FunctionName
)。trigger_url
: The URL to trigger $FunctionName
. trigger_url
:触发$FunctionName
的 URL。 Note that this property does not honour custom routes.请注意,此属性不支持自定义路由。The url you can get via Get Function URL
named trigger_url
, seems you could not be able to get all of them in a function app, but you can get it for one specific function, See : Web Apps - List Function Secrets , the trigger_url
in the response body is what you want.您可以通过名为trigger_url
Get Function URL
的 url 似乎无法在函数应用程序中获取所有这些Get Function URL
,但是您可以为一个特定函数获取它,请参阅: Web Apps - List Function Secrets中的trigger_url
响应体就是你想要的。
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/functions/{functionName}/listsecrets?api-version=2016-08-01
Response body:响应体:
{
"key": "xxxxxxxxxxxxxxxxxxx",
"trigger_url": "https://xxxxx.azurewebsites.net/api/HttpTrigger1?code=xxxxxxxxxxxxxxx"
}
Note : If you get an error like below, you need to add an application setting AzureWebJobsSecretStorageType : Files
for your function app.注意:如果出现如下错误,则需要添加应用程序设置AzureWebJobsSecretStorageType : Files
函数应用的AzureWebJobsSecretStorageType : Files
。
{
"error": {
"code": "Conflict",
"message": "System.InvalidOperationException: Runtime keys are stored on blob storage. This API doesn't support this configuration. Please change Environment variable AzureWebJobsSecretStorageType value to 'Files'. For more info, visit https://aka.ms/funcsecrets\r\n at Kudu.Core.Functions.FunctionManager.<GetKeyObjectFromFile>d__9`1.MoveNext() in C:\\Kudu Files\\Private\\src\\master\\Kudu.Core\\Functions\\FunctionManager.cs:line 141\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Kudu.Core.Functions.FunctionManager.<GetFunctionSecretsAsync>d__12.MoveNext() in C:\\Kudu Files\\Private\\src\\master\\Kudu.Core\\Functions\\FunctionManager.cs:line 220\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Kudu.Services.Functions.FunctionController.<GetSecrets>d__12.MoveNext() in C:\\Kudu Files\\Private\\src\\master\\Kudu.Services\\Functions\\FunctionController.cs:line 141"
}
}
I got it.我知道了。 In the data for the function itself, the route is part of the properties.config object.在函数本身的数据中,路由是 properties.config 对象的一部分。
Request should look like this: https://management.azure.com/subscriptions/{subscriptionid}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{functionAppName}/functions/{functionName}?api-version=2016-08-01
请求应如下所示: https://management.azure.com/subscriptions/{subscriptionid}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{functionAppName}/functions/{functionName}?api-version=2016-08-01
: https://management.azure.com/subscriptions/{subscriptionid}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{functionAppName}/functions/{functionName}?api-version=2016-08-01
In the return value is a properties
object, and within that is config
object.返回值是一个properties
对象,其中是config
对象。 Underneath that is the route
property which contains the trigger endpoint.在它下面是包含触发器端点的route
属性。
In Powershell, it's this:在Powershell中,它是这样的:
$functionData = Invoke-RestMethod -Method Get -Uri $functionName -Headers $accessTokenHeader
$triggerUrl = "https://$functionAppName.azurewebsites.net/api/" + $functionData.properties.config.route
You can test it here: https://docs.microsoft.com/en-us/rest/api/appservice/webapps/getfunction你可以在这里测试: https : //docs.microsoft.com/en-us/rest/api/appservice/webapps/getfunction
Hope this helps someone else!希望这对其他人有帮助! Thanks to those who contributed.感谢那些做出贡献的人。
快速提示:如果您可以使用 Get-AzContext 获取 azure 上下文,则可以像这样(Get-AzContext).TokenCache[0].ReadItems().AccessToken
标头的访问令牌: (Get-AzContext).TokenCache[0].ReadItems().AccessToken
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.