是否可以选择从 Azure 函数的部署中获取输出值处的事件网格触发器 url + 键? [英] Is there a option to get the event grid trigger url + key at output value from the deployment of a Azure Function?

查看:16
本文介绍了是否可以选择从 Azure 函数的部署中获取输出值处的事件网格触发器 url + 键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以选择从 Azure 函数的部署中获取输出值处的事件网格触发器 url + 键?

Is there a option to get the event grid trigger url + key at output value from the deployment of a Azure Function?

我们想做的场景如下:- 我们通过 ARM 在 VSTS 版本中部署功能服务.- 部署了 Function 服务后,我们部署了事件网格订阅.

The scenario we would like to do is as followed: - We deploy a Function Service in a VSTS release via ARM. - With the Function service deployed we deploy the event grid subscription.

谢谢,施拉达·阿格拉瓦尔

Thanks, Shraddha Agrawal

推荐答案

是的,有一种方法可以使用 REST API 来获取函数访问代码.以下是步骤:

Yes, there is a way using the REST API to obtain a function access code. The following are the steps:

  1. 假设函数的名称是 EventGridTrigger2 和 run.csx:

  1. Let assume a name of the function is EventGridTrigger2 and the run.csx:

#r "Newtonsoft.Json"

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

public static void Run(JObject eventGridEvent, TraceWriter log)
{
    log.Info(eventGridEvent.ToString(Formatting.Indented));

}

和function.json文件:

and the function.json file:

    {
        "bindings": [
        {
          "type": "eventGridTrigger",
          "name": "eventGridEvent",
          "direction": "in"
        }
       ],
       "disabled": false
    }

如您所见,上述绑定是无类型的,适用于任何输出架构,例如 InputEventSchemaEventGridSchema(默认架构)和 CloudEventV01Schemaem>(修复一些错误后).

As you can see the above bindings is untyped, which will work for any output schema such as InputEventSchema, EventGridSchema (default schema) and CloudEventV01Schema (after fixing some bug).

  1. 创建的订阅的 destination 属性如下所示:

"destination": {
    "properties": {
      "endpointUrl": null,
      "endpointBaseUrl": "https://myFunctionApp.azurewebsites.net/admin/extensions/EventGridExtensionConfig"
    },
    "endpointType": "WebHook"
  },

请注意,Azure EventGrid 触发器的完整subscriberUrl 具有以下格式,其中查询字符串包含用于将请求路由到正确函数的参数:

Note, that the full subscriberUrl for Azure EventGrid trigger has the following format, where the query string contains parameters for routing request to the properly function:

https://{FunctionApp}.azurewebsites.net/admin/extensions/EventGridExtensionConfig?functionName={FunctionName}&code={masterKey}

为了创建订阅者,我们必须使用包含查询字符串的完整subscriberUrl.此时,唯一未知的值是masterKey.

For creating a subscriber we have to use its full subscriberUrl included a query string. In this moment, the only unknown value is the masterKey.

  1. 要获取函数应用(主机)主密钥,我们必须使用管理 REST API 调用:

  1. To obtain a Function App (Host) masterkey we have to use a management REST API call:

https://management.azure.com/subscriptions/{mySubscriptionId}/resourceGroups/{myResGroup}/providers/Microsoft.Web/sites/{myFunctionApp}/functions/admin/masterkey?api-version=2016-08-01

响应格式如下:

    {
       "masterKey": "*************************************************"
    }

请注意,此调用需要身份验证承载令牌.

Note, that the authentication Bearer token is required for this call.

一旦我们拥有 FunctionApp(主机)的主密钥,我们就可以将它用于该主机内的任何功能.

Once we have a masterKey for the FunctionApp (host), we can use it for any function within this host.

这篇关于是否可以选择从 Azure 函数的部署中获取输出值处的事件网格触发器 url + 键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆