如何在azure bicep部署模板中获取linux应用服务的主机url



我使用如下所示的肱二头肌资源创建了一个应用服务

name: '${appName}'
location: location
kind: 'linux,container,fnapp'
properties: {
serverFarmId: servicePlan.id
siteConfig: {
linuxFxVersion: 'DOCKER|${dockerLocation}'
healthCheckPath: '/api/healthcheck'
alwaysOn: true
appSettings: [
...
]
}
}
}

按预期工作,但是我想获得该应用程序服务的url,用作我的apim服务的后端url。

我目前使用var fnAppUrl = 'https://${fnApp.name}.azurewebsites.net/api'。是否有任何方法可以从功能应用程序资源的直接输出中获得默认url,即var fnAppUrl = fnApp.url或类似的东西?

TIA

此基路径无特定属性,通过配置host.jsonextensions.http.routePrefix的值来设置。(文档:https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-http-webhook?tabs=in-process%2Cfunctionsv2&轴心= programming-language-csharp # hostjson-settings)

如果不需要/api前缀,那么在您的Bicep文件中使用以下输出就足够了:

resource myFunctionApp 'Microsoft.Web/sites@2021-03-01' = {
// ...
}
output functionBaseUrl string = 'https://${myFunctionApp.properties.defaultHostName}'

然后在host.json中确保routePrefix设置为空字符串:

{
"extensions": {
"http": {
"routePrefix": ""
}
}
}

如果你想使用路由前缀,你需要将它与默认主机名结合使用:

resource myFunctionApp 'Microsoft.Web/sites@2021-03-01' = {
// ...
}
output functionBaseUrl string = 'https://${myFunctionApp.properties.defaultHostName}/api'

据我所知,没有直接的url可以从函数中获得。但是你也可以这样写:

output functionBaseUrl string = 'https://${function.properties.defaultHostName}/api'

这将导致默认主机名包括"azurewebsites.net"部分。

查看template.bicep中的完整示例:https://github.com/DSpirit/azure-functions-bicep-outputs-host

最新更新