如何使用Azure Bicep将APIM连接到Azure Function应用程序?

bttbmeg0  于 2023-06-07  发布在  其他
关注(0)|答案(1)|浏览(216)

我正在尝试将Azure Function应用程序(其中有一个Sping Boot 应用程序)与Azure API管理连接。我可以使用Azure UI来实现这一点。
但是,当我使用Azure Bicep尝试此操作时,我必须手动指定要在APIM中显示的所有API。

param location string = resourceGroup().location

resource bicep_poc 'Microsoft.ApiManagement/service@2022-09-01-preview' = {
  name: 'bicep-poc'
  location: location
  sku: {
    name: 'Consumption'
    capacity: 0
  }
  identity: {
    type: 'SystemAssigned'
  }
  properties: {
    publisherEmail: 'abc@xyz.com'
    publisherName: 'abcd'
  }
}

// send apis
resource bicep_poc_bicep_fa_demo 'Microsoft.ApiManagement/service/apis@2022-09-01-preview' = {
  parent: bicep_poc
  name: 'bicep-fa-demo'
  properties: {
    displayName: 'bicep-fa-demo api function'
    apiRevision: '1'
    description: 'Import from "bicep-fa-demo" Function App'
    subscriptionRequired: false
    path: 'bicep-fa-demo/hello_1a'
    protocols: [
      'https'
    ]
    isCurrent: true
  }
}

resource bicep_poc_bicep_fa_demo_get_hello_world 'Microsoft.ApiManagement/service/apis/operations@2022-09-01-preview' = {
  parent: bicep_poc_bicep_fa_demo
  name: 'get-hello-world'
  properties: {
    displayName: 'hello-world'
    method: 'GET'
    urlTemplate: '/hello-world'
    templateParameters: []
    responses: []
  }
}

resource bicep_poc_bicep_fa_demo_get_hello_world_policy 'Microsoft.ApiManagement/service/apis/operations/policies@2022-09-01-preview' = {
  parent: bicep_poc_bicep_fa_demo_get_hello_world
  name: 'policy'
  properties: {
    value: '<policies>\r\n  <inbound>\r\n    <base />\r\n    <set-backend-service id="apim-generated-policy" backend-id="bicep-fa-demo" />\r\n  </inbound>\r\n  <backend>\r\n    <base />\r\n  </backend>\r\n  <outbound>\r\n    <base />\r\n  </outbound>\r\n  <on-error>\r\n    <base />\r\n  </on-error>\r\n</policies>'
    format: 'xml'
  }
}

这里我需要手动添加Microsoft.ApiManagement/service/apis/operations
有没有什么直接的方法可以像UI一样,通过连接lambda来创建Http触发器的所有api,并将其连接到后端(这里是function app)?

mspsb9vt

mspsb9vt1#

除非您传递一个swagger模式,否则没有直接的方法,但是您可以通过分解为像this这样的模块来简化简单的GET操作。在模块内部,我声明了API、操作、策略和Web测试。
我的链接二头肌来自的存储库,显示了完整的端到端Azure Functions + APIM实现...可能对你有用。

相关问题