如何使用 arm 模板在 azure 函数中创建混合连接
How to create hybrid connection inside azure function using arm template
我已经使用 arm 模板创建了 azure 函数应用程序。但是我想在 azure 函数的网络下创建一些混合连接,如下所示:
那么,有人可以建议我怎么做吗?
我这边的例子:
为您的混合连接终结点添加数组列表:
"parameters": {
......
"endpoint": {
"defaultValue": [
"test6:3306",
"test6:8081",
"test6:8082"
],
"type": "Array"
}
},
在资源部分复制用法:
{
"type": "Microsoft.Relay/namespaces/HybridConnections",
"apiVersion": "2017-04-01",
"name": "[concat(parameters('relayName'), '/', copyIndex())]",
"location": "Central US",
"dependsOn": [
"[resourceId('Microsoft.Relay/namespaces', parameters('relayName'))]"],
"properties": {
"requiresClientAuthorization": false,
"userMetadata": "[[{\"key\":\"endpoint\",\"value\":\"[parameters('endpoint')[copyIndex()]]\"}]"
},
"copy": {
"name": "datacopy",
"count": 3
}
},
{
"type": "Microsoft.Relay/namespaces",
"apiVersion": "2018-01-01-preview",
"name": "[parameters('relayName')]",
"location": "Central US",
"sku": {
"name": "Standard",
"tier": "Standard"
},
"properties": {}
}
这是我的参考资料:
-
Link existing hybrid connection to an azure web app through ARM-template
-
要使用二头肌为网络创建混合连接,您需要:
param appServiceName string
var cfg = json(loadTextContent('../../bicepConsts.json'))
var hc = cfg.HybridConnection
resource appService 'Microsoft.Web/sites@2021-02-01' existing = {
name: appServiceName
}
var relayId = resourceId(hc.ResourceGroup, 'Microsoft.Relay/namespaces', hc.Namespace)
var connectionId = '${relayId}/hybridConnections/${hc.Name}'
var senderKeyName = 'defaultSender'
var key = listKeys('${connectionId}/authorizationRules/${senderKeyName}', '2017-04-01').primaryKey
resource hybridConnection 'Microsoft.Web/sites/hybridConnectionNamespaces/relays@2021-02-01' = {
name: '${appService.name}/${hc.Namespace}/${hc.Name}'
location: hc.NamespaceLocation
dependsOn: [
appService
]
properties: {
serviceBusNamespace: hc.Namespace
relayName: hc.Name
relayArmUri: connectionId
hostname: hc.Host
port: hc.Port
sendKeyName: senderKeyName
sendKeyValue: key
serviceBusSuffix: '.servicebus.windows.net'
}
}
这个 bicepConsts 文件包含这样的想法:
{
"..." : "...",
"HybridConnection": {
"ResourceGroup": "resource group of your HybridConnection from Azure",
"Name": "Name of hybrid connection",
"Namespace": "Namespace of hybrid connection",
"NamespaceLocation": "Location (e.g. 'West US 2') of your hybrid connection namespace",
"Host": "Host of your hybrid connection",
"Port": "Port of your hybrid connection AS INTEGER!",
}
}
我已经使用 arm 模板创建了 azure 函数应用程序。但是我想在 azure 函数的网络下创建一些混合连接,如下所示:
那么,有人可以建议我怎么做吗?
我这边的例子:
为您的混合连接终结点添加数组列表:
"parameters": {
......
"endpoint": {
"defaultValue": [
"test6:3306",
"test6:8081",
"test6:8082"
],
"type": "Array"
}
},
在资源部分复制用法:
{
"type": "Microsoft.Relay/namespaces/HybridConnections",
"apiVersion": "2017-04-01",
"name": "[concat(parameters('relayName'), '/', copyIndex())]",
"location": "Central US",
"dependsOn": [
"[resourceId('Microsoft.Relay/namespaces', parameters('relayName'))]"],
"properties": {
"requiresClientAuthorization": false,
"userMetadata": "[[{\"key\":\"endpoint\",\"value\":\"[parameters('endpoint')[copyIndex()]]\"}]"
},
"copy": {
"name": "datacopy",
"count": 3
}
},
{
"type": "Microsoft.Relay/namespaces",
"apiVersion": "2018-01-01-preview",
"name": "[parameters('relayName')]",
"location": "Central US",
"sku": {
"name": "Standard",
"tier": "Standard"
},
"properties": {}
}
这是我的参考资料:
Link existing hybrid connection to an azure web app through ARM-template
要使用二头肌为网络创建混合连接,您需要:
param appServiceName string
var cfg = json(loadTextContent('../../bicepConsts.json'))
var hc = cfg.HybridConnection
resource appService 'Microsoft.Web/sites@2021-02-01' existing = {
name: appServiceName
}
var relayId = resourceId(hc.ResourceGroup, 'Microsoft.Relay/namespaces', hc.Namespace)
var connectionId = '${relayId}/hybridConnections/${hc.Name}'
var senderKeyName = 'defaultSender'
var key = listKeys('${connectionId}/authorizationRules/${senderKeyName}', '2017-04-01').primaryKey
resource hybridConnection 'Microsoft.Web/sites/hybridConnectionNamespaces/relays@2021-02-01' = {
name: '${appService.name}/${hc.Namespace}/${hc.Name}'
location: hc.NamespaceLocation
dependsOn: [
appService
]
properties: {
serviceBusNamespace: hc.Namespace
relayName: hc.Name
relayArmUri: connectionId
hostname: hc.Host
port: hc.Port
sendKeyName: senderKeyName
sendKeyValue: key
serviceBusSuffix: '.servicebus.windows.net'
}
}
这个 bicepConsts 文件包含这样的想法:
{
"..." : "...",
"HybridConnection": {
"ResourceGroup": "resource group of your HybridConnection from Azure",
"Name": "Name of hybrid connection",
"Namespace": "Namespace of hybrid connection",
"NamespaceLocation": "Location (e.g. 'West US 2') of your hybrid connection namespace",
"Host": "Host of your hybrid connection",
"Port": "Port of your hybrid connection AS INTEGER!",
}
}