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

查看:109
本文介绍了是否可以从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版本中部署了功能服务. -部署了功能服务后,我们将部署事件网格订阅.

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.

谢谢, Shraddha Agrawal

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:

#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
    }

如您所见,上述绑定是未类型化的,它将适用于任何输出架构,例如 InputEventSchema EventGridSchema (默认架构)和 CloudEventV01Schema (修复了一些错误之后).

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. 所创建的Subscription的 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": "*************************************************"
    }

请注意,此呼叫需要身份验证 Bearer令牌.

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天全站免登陆