【问题标题】:Azure generate URL for a standard Logic app with connection to CosmosDBAzure 为连接到 CosmosDB 的标准逻辑应用生成 URL
【发布时间】:2021-10-22 02:42:48
【问题描述】:

我在标准逻辑应用中有一个具有 HTTP 触发器的工作流。当工作流被触发时,工作流会从 CosmosDB 中检索一些数据。比如:

之前的方法需要有一个 API 连接。我已经创建并部署了一个“V2”API 连接。我们就叫它myCosmosCon

此外,在我的逻辑应用程序的 ARM 模板中,我已经将我的连接 API 的 connectionRuntimeUrl(到 myCosmosCon)添加到 appSettings(配置):

....
"siteConfig": {
      "appSettings": [
       {
          "name": "subscriptionId",
          "value": "[subscription().subscriptionId]"
       },
       {
          "name": "resourceGroup_name",
          "value": "[resourceGroup().name]"
       },
       {
            "name": "location_name",
            "value": "[resourceGroup().location]"
       },
       {
            "name": "connectionRuntimeUrl",
            "value": "[reference(resourceId('Microsoft.Web/connections', parameters('connection_name')),'2016-06-01', 'full').properties.connectionRuntimeUrl]"
      },
      .....               
      ]
    }, 

然后我在connections.json中写了以下内容:

{
"managedApiConnections": {
  "documentdb": {
    "api": {
      "id": "/subscriptions/@appsetting('subscriptionId')/providers/Microsoft.Web/locations/@appsetting('location_name')/managedApis/documentdb"
    },
    "connection": {
      "id": "/subscriptions/@appsetting('subscriptionId')/resourceGroups/@appsetting('resourceGroup_name')/providers/Microsoft.Web/connections/myCosmosCon"
    },
    "connectionRuntimeUrl": "@appsetting('connection_runtimeUrl')",
    "authentication": {
        "type": "ManagedServiceIdentity"
    }
  }
}

}

现在,当我部署逻辑应用程序、工作流等的 ARM 模板时,我没有发现任何错误,工作流看起来也不错。唯一的问题是没有生成指向 HTTP 触发器的 URL 链接,我无法运行程序。

但是,如果我将connections.json 文件中的connection_runtimeUrl 更改为具有实际值;看起来像:

      "connectionRuntimeUrl": "https://xxxxxxxxxxxxx.xx.common.logic-norwayeast.azure-apihub.net/apim/myCosmosCon/xxxxxxxxxxxxxxxxxxxxxxxx/",

URL 是直接生成的,我可以简单地运行工作流。 之后,如果我按原样返回connection_runtimeUrl(调用appsettings()),它仍然有效!该链接也保留在那里。

看起来当我部署 Logic 应用程序和工作流时,connections.json 没有编译或调用,所以 Azure 认为有错误并且不生成链接。

你知道如何解决这个问题吗??

谢谢!

【问题讨论】:

  • 您是在尝试提取 Web 应用或 Cosmos DB 帐户的 URL 吗?
  • 不,我正在尝试提取 API 连接(连接到 Cosmos DB)的 URL。因此,在 appsettings 下的逻辑应用程序的 ARM 模板中,我有以下内容: { "name": "connectionRuntimeUrl", "value": "[reference(resourceId('Microsoft.Web/connections', parameters('connection_name')) ,'2016-06-01', 'full').properties.connectionRuntimeUrl]" },
  • 您能看到connectionRuntimeUrl appsetting 具有期望/正确的值吗?同样在创建 api 连接时,您还需要为其创建访问策略。
  • connectionRuntimeUrl 在 appsettings 中的值与 API 连接属性下的值完全相同。我需要创建访问策略是什么意思?在哪里?和谁?

标签: azure azure-cosmosdb arm-template azure-connect azure-logic-app-standard


【解决方案1】:

我遇到了完全相同的问题/错误。我看到的唯一解决方法是将工作流程部署两次。第一次使用指向虚拟连接的实际 URL,第二次使用 appsetting 引用。

【讨论】:

    【解决方案2】:

    不确定,但可能是问题所在: 在为逻辑应用标准创建连接 api 时,还需要在连接 api 级别为运行逻辑应用标准的系统分配的身份创建访问策略。

    param location string = resourceGroup().location
    param cosmosDbAccountName string
    param connectorName string = '${cosmosDbAccountName}-connector'
    
    // The principalid of the logic app standard system assigned identity
    param principalId string
    
    // get a reference to the cosmos db account
    resource cosmosDbAccount 'Microsoft.DocumentDB/databaseAccounts@2021-06-15' existing = {
      name: cosmosDbAccountName
    }
    
    // create the related connection api
    resource cosmosDbConnector 'Microsoft.Web/connections@2016-06-01' = {
      name: connectorName
      location: location
      kind: 'V2'
      properties: {
        displayName: connectorName
        parameterValues: {
          databaseAccount: cosmosDbAccount.name
          accessKey: listKeys(cosmosDbAccount.id, cosmosDbAccount.apiVersion).primaryMasterKey
        }
        api: {
          id: 'subscriptions/${subscription().subscriptionId}/providers/Microsoft.Web/locations/${location}/managedApis/documentdb'
        }
      }
    }
    
    // Grant permission to the logic app standard to access the connection api
    resource cosmosDbConnectorAccessPolicy 'Microsoft.Web/connections/accessPolicies@2016-06-01' = {
      name: '${cosmosDbConnector.name}/${principalId}'
      location: location
      properties: {
        principal: {
          type: 'ActiveDirectory'
          identity: {
            tenantId: subscription().tenantId
            objectId: principalId
          }
        }
      }
    }
    
    output connectionRuntimeUrl string = reference(cosmosDbConnector.id, cosmosDbConnector.apiVersion, 'full').properties.connectionRuntimeUrl
    
    

    【讨论】:

    • 不幸的是它仍然无法正常工作。我的 API 连接中有访问策略,但它仍然无法正常工作。我开始觉得这是微软方面的一个bug
    猜你喜欢
    • 2022-11-10
    • 2021-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-27
    • 1970-01-01
    • 2019-06-15
    • 2020-05-01
    相关资源
    最近更新 更多