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

Azure新手求助:Event Grid对接Service Bus时端点验证失败

Fixing "Endpoint Validation Failed" Error When Creating Event Grid Subscription for Azure Service Bus

Hey there! I’ve hit this exact endpoint validation snag before when setting up Event Grid with Azure Service Bus and Functions, so let’s break down the most common fixes to get you unblocked:

  • Double-check your Azure Function trigger URL
    Make sure you’re using the full, correct trigger URL from your Function App. You can grab this directly from the Function’s Overview page in the Azure Portal—don’t manually type or modify it, especially the ?code=xxx function key part. A tiny typo here is one of the most frequent causes of validation failures.

  • Verify permissions for Event Grid to access your Function

    • If you’re using function keys: Ensure the key included in the URL has the right permissions (it should have "invoke" access, which is the default for function-level keys).
    • If you’re using Azure AD authentication: Head to your Function App’s Access control (IAM) blade and add the Event Grid service principal with a role like Function App Contributor or a custom role that grants the Microsoft.Web/sites/functions/invoke permission. Also, confirm you haven’t disabled anonymous access without setting up proper AAD authorization for Event Grid.
  • Check network and firewall restrictions

    • If your Function App is in a VNet or has firewall rules enabled, you need to allow Event Grid to reach it. Add Event Grid’s service tag (EventGrid) to your Function App’s Networking > Access restrictions allowed list.
    • For VNet-integrated functions, ensure your subnet has outbound access to Event Grid endpoints, or add Event Grid’s region-specific IP ranges to your network security group rules.
  • Ensure your function handles Event Grid validation requests
    Event Grid sends a subscription validation request when you create the subscription, and your function must respond correctly to pass validation. If your function code doesn’t handle this, the check will fail. Here’s a quick C# example to handle the validation:

    [FunctionName("ServiceBusEventGridHandler")]
    public static async Task<IActionResult> Run(
        [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
        ILogger log)
    {
        var requestBody = await new StreamReader(req.Body).ReadToEndAsync();
        var events = JsonConvert.DeserializeObject<EventGridEvent[]>(requestBody);
    
        // Handle validation event
        if (events?.Any(e => e.EventType == "Microsoft.EventGrid.SubscriptionValidationEvent") == true)
        {
            var validationEvent = events.First(e => e.EventType == "Microsoft.EventGrid.SubscriptionValidationEvent");
            var validationData = JsonConvert.DeserializeObject<SubscriptionValidationData>(validationEvent.Data.ToString());
            return new OkObjectResult(new SubscriptionValidationResponse
            {
                ValidationResponse = validationData.ValidationCode
            });
        }
    
        // Process actual Service Bus events here
        log.LogInformation("Processing Service Bus event from Event Grid");
        return new OkResult();
    }
    
    // Helper classes for validation
    public class SubscriptionValidationData { public string ValidationCode { get; set; } }
    public class SubscriptionValidationResponse { public string ValidationResponse { get; set; } }
    

    For other languages (like Python or JavaScript), the logic is similar—parse the incoming request, look for the validation event, and return the validation code in the response.

  • Confirm resource region alignment
    While cross-region setups are supported, sticking to the same region for your Service Bus namespace, Function App, and Event Grid subscription can eliminate network latency or cross-region permission issues that might trigger validation failures, especially when you’re just getting started.

If you try these steps and still run into issues, check the Azure Activity Log for the failed deployment—it should have more detailed error messages beyond the truncated "Code:va..." part to narrow things down further.

内容的提问来源于stack exchange,提问作者Swati Patil

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 07:34:11