You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否从Azure Function部署输出中获取Event Grid触发URL与密钥?

Absolutely! You can absolutely retrieve the Event Grid trigger URL and access key from your Azure Function's ARM deployment outputs in Azure DevOps (formerly VSTS) to use in your subsequent Event Grid subscription deployment. Here's how to make this happen smoothly:

Step 1: Define Outputs in Your Function App ARM Template

First, you need to explicitly add output values to your ARM template that capture the trigger URL and key. This exposes the values so your pipeline can pick them up post-deployment.

  • Capture the full Event Grid trigger URL:
    Use the listCallbackUrl ARM template function to fetch the complete trigger URL (which includes the access key by default). Here’s what the output block would look like:

    "outputs": {
      "eventGridTriggerUrl": {
        "type": "string",
        "value": "[listCallbackUrl(resourceId('Microsoft.Web/sites/functions', parameters('functionAppName'), parameters('eventGridFunctionName')), '2022-09-01').url]"
      }
    }
    
  • Capture the trigger-specific access key (optional):
    If you need the key separately (e.g., for validation or other integrations), you can retrieve the function's default key using the listKeys function:

    "outputs": {
      "eventGridTriggerKey": {
        "type": "string",
        "value": "[listKeys(resourceId('Microsoft.Web/sites/functions', parameters('functionAppName'), parameters('eventGridFunctionName')), '2022-09-01').functionKeys.default]"
      }
    }
    

    Note: The listCallbackUrl result already includes the key, so you may not need this separate output unless you have a specific use case.

Step 2: Capture Deployment Outputs in Azure DevOps

Once your ARM template deployment runs in your release pipeline, you need to tell Azure DevOps to save these outputs as pipeline variables:

  1. Open your Azure DevOps release pipeline and navigate to the ARM Template Deployment task.
  2. Scroll to the Outputs section and check the box labeled Publish deployment outputs to pipeline.
  3. Each output from your template will be available as a pipeline variable using the format $(<DeploymentTaskName>.outputs['<OutputName>']). For example, if your deployment task is named DeployFunctionApp and your output is eventGridTriggerUrl, the variable becomes $(DeployFunctionApp.outputs['eventGridTriggerUrl']).
Step 3: Use the Variables for Event Grid Subscription Deployment

Now you can reference these variables in the task that deploys your Event Grid subscription—here are two common approaches:

Using another ARM template for Event Grid

Pass the trigger URL as a parameter to your Event Grid subscription template:

"parameters": {
  "functionEndpointUrl": {
    "type": "string",
    "metadata": {
      "description": "The endpoint URL for the Azure Function Event Grid trigger"
    }
  }
},
"resources": [
  {
    "type": "Microsoft.EventGrid/systemTopics/eventSubscriptions",
    "name": "[concat(parameters('systemTopicName'), '/', parameters('eventSubscriptionName'))]",
    "apiVersion": "2022-06-15",
    "properties": {
      "destination": {
        "endpointType": "AzureFunction",
        "properties": {
          "resourceId": "[parameters('functionAppResourceId')]",
          "endpointUrl": "[parameters('functionEndpointUrl')]"
        }
      },
      "filter": {
        "includedEventTypes": ["Microsoft.Storage.BlobCreated"]
      }
    }
  }
]

In the Azure DevOps task for this template, map the pipeline variable you captured earlier to the functionEndpointUrl parameter.

Using Azure CLI or PowerShell

If you prefer scripting, reference the variable directly in your CLI/PowerShell command:

az eventgrid event-subscription create \
  --name "myStorageBlobSubscription" \
  --source-resource-id "/subscriptions/<your-sub-id>/resourceGroups/<your-rg>/providers/Microsoft.Storage/storageAccounts/<your-storage-account>" \
  --endpoint "$(DeployFunctionApp.outputs['eventGridTriggerUrl'])"
Key Things to Remember
  • Ensure the service principal used by your Azure DevOps pipeline has the Microsoft.Web/sites/functions/listkeys/action permission on the function app—this is required to fetch the trigger URL and keys.
  • Use a compatible API version in your ARM template (the examples use 2022-09-01 for functions; adjust to the latest version that works with your resources).
  • Test the pipeline variables first to confirm they’re populated correctly—you can add a PowerShell task to echo the variables and verify their values before deploying the Event Grid subscription.

内容的提问来源于stack exchange,提问作者Agrawal Shraddha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 03:59:12