【问题标题】:Python Function App connections using managed identity使用托管标识的 Python 函数应用程序连接
【发布时间】:2022-08-02 19:35:16
【问题描述】:

无法使用 Python Azure 函数为托管标识设置服务总线的连接信息。

我在 function.json 中有以下设置

{
  \"scriptFile\": \"__init__.py\",
  \"bindings\": [
    {
      \"name\": \"msg\",
      \"type\": \"serviceBusTrigger\",
      \"direction\": \"in\",
      \"queueName\": \"myinputqueue\",
      \"connection\": \"MySvcConn\"
    }
  ]
}

在 Azure 门户的应用程序设置中,我设置了

\"MySvcConn__fullyQualifiedNamespace\":\"mysvcns.servicebus.windows.net\"

我收到消息

\"Microsoft.Azure.ServiceBus: Value for the connection string 
parameter name \'mysvcns.servicebus.windows.net\' was not found. (Parameter \'connectionString\').

使用的运行时版本 ~4

host.json 配置

{
  \"version\": \"2.0\",
  \"logging\": {
    \"applicationInsights\": {
      \"samplingSettings\": {
        \"isEnabled\": true,
        \"excludedTypes\": \"Request\"
      }
    }
  },
  \"extensionBundle\": {
    \"id\": \"Microsoft.Azure.Functions.ExtensionBundle\",
    \"version\": \"[2.*, 3.0.0)\"
  }
}
  • 你能检查一下安装包:docs.microsoft.com/en-us/azure/azure-functions/… 吗?
  • azure 门户部署旧版本的扩展程序 \"version\": \"[2.*, 3.0.0)\",其中推荐的版本是 \"[3.3.0, 4.0.0)\"。如何更新扩展
  • 您应该能够在本地编辑 host.json 然后重新部署。

标签: python azure-functions


【解决方案1】:
  • 要使用托管标识连接到服务总线,我们首先将servicebus data receiver 角色添加到访问控制。

  • 然后将连接设置添加到名称下的应用程序设置中 ServiceBusConnection__fullyQualifiedNamespace 并将连接值添加为<Name_of_servicebus>.servicebus.windows.net

  • 上述设置将使用托管标识将函数应用连接到服务总线,而不使用连接字符串。

参考这个documentation

【讨论】:

  • 根据答案我修改了function.json。从此文件中删除了连接。现在我收到此错误 Microsoft.Azure.WebJobs.ServiceBus: Microsoft Azure WebJobs SDK ServiceBus 连接字符串“AzureWebJobsServiceBus”丢失或为空。我的应用设置有一个“ServiceBusConnection__fullyQualifiedNamespace”,值设置为“mysvcns.servicebus.windows.net”
  • 尝试使用 ServiceBusConnection:fullyQualifiedNamespace 而不是 ServiceBusConnection__fullyQualifiedNamespace
  • 应用程序设置不允许在名称字段中使用“:”。仅允许的字符是字母、数字和“_”
  • 我刚刚在函数应用 i.imgur.com/hDx9Kiz.png 中添加了 ServiceBusConnection:fullyQualifiedNamespace
  • @user2603610 - 请不要在 cmets 中发布大量后续细节。改为编辑您的问题。此外,请务必包含格式正确的文本,而不是文本图像。
【解决方案2】:

能够解决这个问题,需要在功能应用程序中为以下设置应用程序设置

ServiceBusConnection__clientID:<managedidenity client id>
ServiceBusConnection__credential:managedidentity
ServiceBusConnection__fullyQualifiedNamespace:<servicebusname>.servicebus.windows.net

上述设置中的“ServiceBusConnection”是function.json文件中的连接名称。

【讨论】:

    猜你喜欢
    • 2020-08-26
    • 2021-08-15
    • 2014-05-14
    • 1970-01-01
    • 1970-01-01
    • 2021-08-03
    • 1970-01-01
    • 1970-01-01
    • 2022-12-19
    相关资源
    最近更新 更多