【问题标题】:Azure function app's signalr_extension is not populated to use in signalR upstreams when creating a function app by Bicep由 Bicep 创建函数应用程序时,Azure 函数应用程序的 signalr_extension 未填充以在 signalR 上游使用
【发布时间】:2022-07-04 20:31:20
【问题描述】:

我通过 Bicep 创建了一个 Azure Function App,并尝试获取 signalr_extension 的值以在无服务器 Azure SignalR 服务的“上游”配置部分中使用。这就是我尝试在二头肌中获取此值的方式:

var signalRKey = listKeys(resourceId('Microsoft.Web/sites/host', funcAppName, 'default'), '2022-03-01').systemkeys.signalr_extension

这是我配置 signalR 服务上游的方式:

urlTemplate: 'https://${funcAppName}.azurewebsites.net/runtime/webhooks/signalr?code=${signalRKey}'

运行二头肌模板会导致以下故障:

在主机运行时遇到错误 (ServiceUnavailable)。

当我从urlTemplate 中删除{signalRKey} 并将其替换为虚构的硬编码值时,signalR 配置成功。

我注意到的另一件事是,在预配函数应用后未填充 singalr_extension 键值。

我在这个练习中遗漏了什么?

【问题讨论】:

    标签: azure azure-functions azure-resource-manager azure-bicep azure-signalr


    【解决方案1】:

    只有在使用 SignalRTrigger 函数部署函数应用后,才会创建 signalr_extension
    如果您同时部署 Function App 和 signalR 服务,则可以预先生成此密钥:

    param functionAppName string
    
    // Create the function app key for signalR
    resource signalRKey 'Microsoft.Web/sites/host/systemkeys@2021-03-01' = {
      name: '${functionAppName}/default/signalr_extension'
      properties: {
        name: 'signalr_extension'
      }
    }
    

    用于生成功能键的 ARM API 只是指向功能应用 API,因此它可能需要一些时间才能可用(请参阅github 上的问题)。

    通过使用模块部署系统密钥和信号器,我设法使其始终如一地工作。
    同样对于在linux 上运行的函数应用,AzureWebJobsStorage 设置是强制性的。

    functionapp-systemkey.bicep 模块:

    param functionAppName string
    param keyName string
    
    resource signalRKey 'Microsoft.Web/sites/host/systemkeys@2021-03-01' = {
      name: '${functionAppName}/default/${keyName}'
      properties: {
        name: keyName
      }
    }
    

    signalr.bicep 模块:

    param location string = resourceGroup().location
    
    param signalRName string
    param functionAppName string
    
    resource signalR 'Microsoft.SignalRService/signalR@2022-02-01' = {
      name: signalRName
      location: location
      sku: {
        name: 'Free_F1'
        tier: 'Free'
        capacity: 1
      }
      properties: {
        features: [
          {
            flag: 'ServiceMode'
            value: 'Serverless'
          }
          {
            flag: 'EnableConnectivityLogs'
            value: 'true'
          }
        ]
        cors: {
          allowedOrigins: [
            '*'
          ]
        }
        tls: {
          clientCertEnabled: false
        }
        upstream: {
          templates: [
            {
              hubPattern: '*'
              eventPattern: '*'
              categoryPattern: '*'
              auth: {
                type: 'None'
              }
              urlTemplate: 'https://${signalRName}.azurewebsites.net/runtime/webhooks/signalr?code=${listKeys(resourceId('Microsoft.Web/sites/host', functionAppName, 'default'), '2022-03-01').systemkeys.signalr_extension}'
            }
          ]
        }
      }
    }
    

    main.二头肌:

    param location string = resourceGroup().location
    
    param storageName string
    param appServicePlanName string
    param functionAppName string
    param signalRName string
    
    resource storage 'Microsoft.Storage/storageAccounts@2021-09-01' = {
      name: storageName
      location: location
      kind: 'StorageV2'
      sku: {
        name: 'Standard_LRS'
      }
      properties: {
        supportsHttpsTrafficOnly: true
        minimumTlsVersion: 'TLS1_2'
      }
    }
    
    resource appServicePlan 'Microsoft.Web/serverfarms@2021-03-01' = {
      name: appServicePlanName
      location: location
      sku: {
        name: 'Y1'
        tier: 'Dynamic'
        size: 'Y1'
        family: 'Y'
        capacity: 0
      }
      kind: 'functionapp'
      properties: {
        perSiteScaling: false
        elasticScaleEnabled: false
        maximumElasticWorkerCount: 1
        isSpot: false
        reserved: true
        isXenon: false
        targetWorkerCount: 0
        targetWorkerSizeId: 0
        zoneRedundant: false
      }
    }
    
    resource functionApp 'Microsoft.Web/sites@2021-03-01' = {
      name: functionAppName
      location: location
      kind: 'functionapp,linux'
      properties: {
        serverFarmId: appServicePlan.id
        clientAffinityEnabled: false
        clientCertEnabled: false
        httpsOnly: true
        siteConfig:{
          linuxFxVersion: 'DOTNET|6.0'
          use32BitWorkerProcess: true
          ftpsState: 'FtpsOnly'
          cors: {
            allowedOrigins: [
              'https://portal.azure.com'
            ]
            supportCredentials: false
          }
          minTlsVersion: '1.2'
          appSettings: [
            {
              name: 'FUNCTIONS_EXTENSION_VERSION'
              value: '~4'
            }
            {
              name: 'FUNCTIONS_WORKER_RUNTIME'
              value: 'dotnet'
            }  
            {
              name: 'AzureWebJobsStorage'
              value: 'DefaultEndpointsProtocol=https;AccountName=${storage.name};AccountKey=${listKeys(storage.id, '2019-06-01').keys[0].value};EndpointSuffix=core.windows.net;'
            }        
          ]
        }    
      }
    }
    
    var signalrKeyName = 'signalr_extension'
    module signalrKey 'modules/functionapp-systemkey.bicep' = {
      name: '${functionAppName}-systemkey-${signalrKeyName}'
      params: {    
        functionAppName: functionApp.name
        keyName: signalrKeyName
      }
    }
    
    module signalr 'modules/signalr.bicep' = {
      name: signalRName
      params: {
        location: location
        functionAppName: functionApp.name
        signalRName: signalRName
      }
      dependsOn:[
        signalrKey
      ]
    }
    

    【讨论】:

    • 感谢您的更新。我将尽快尝试您的更新解决方案。但是,我收到此警告:资源类型“Microsoft.Web/sites/host/systemkeys@2021-03-01”没有可用类型。二头肌(BCP081)我应该忽略它吗?
    • 我根据您的输入更新了我的二头肌模板,但问题仍然存在!错误消息:从主机运行时遇到错误 (ServiceUnavailable)。
    • 发生在 functionapp-systemkey.bicep 模块中。
    • 你能试试运行我的吗?只是试图隔离问题。让我也试试 dotnet-isolated
    • Microsoft 的 Azure 支持团队已在应用服务计划中调查此问题。他们还没有回复我。
    【解决方案2】:

    此功能在应用服务计划中不可用且不可行。 signalr_extension 必须在部署函数应用和 signalR 后手动填充。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-29
      • 2021-07-14
      • 1970-01-01
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多