如何从 ADF 调用 Azure 函数并将参数传递给函数

问题描述 投票:0回答:1

我有一个用 Python 编写的 Azure 函数。该函数将DatabaseName、CompanyId、TeamId 和AssessmentId 作为参数。我需要从 ADF 调用此 Azure 函数。我使用 ADF 中的 Azure 函数活动来调用此函数并使用管道参数传递参数。我尝试了多种方法,但一切都导致了以下错误 -

在“https://fun-cus-textprep-dev.azurewebsites.net”上调用“POST”时,调用提供的 Azure 函数“text Generationtrigger?DatabaseName=devenv&CompanyId=123&TeamId=456&AssessmentId=789”失败,状态为“NotFound”,并且消息 - “调用 Azure 函数失败,并显示 HttpStatusCode - NotFound。”。

我尝试在 Postman 上测试函数端点,它运行成功。使用的查询 - POST 请求:https://fun-cus-textprep-dev.azurewebsites.net/text Generationtrigger?DatabaseName=devenv&CompanyId=123&TeamId=456&AssessmentId=789

从 ADF 调用我的 Azure 函数所采取的步骤:

  1. 使用了Azure功能活动
  2. 创建指向 Azure 函数应用的链接服务并选择作为链接服务
  3. 函数名称:(尝试了两种方式)
a. textgenerationtrigger (Just the function name)
 b. textgenerationtrigger ?DatabaseName=@{toLower(pipeline().parameters.DatabaseName)}&CompanyId=@{pipeline().parameters.CompanyId}&TeamId=@{pipeline().parameters.TeamId}&AssessmentId=@{pipeline().parameters.AssessmentId} (function name with query parameters)
  1. 方式:邮寄
  2. 身体:(尝试了两种方法)
   a. {
   "DatabaseName": "@{pipeline().parameters.DatabaseName}",
   "CompanyId": "@{pipeline().parameters.CompanyId}",
   "TeamId": "@{pipeline().parameters.TeamId}",
   "AssessmentId": "@{pipeline().parameters.AssessmentId}"
   } (when using just the function name in function name section)
   b. {} (When using function name with query parameters)

预期结果是 Azure 函数端点以与通过 Postman ping 时成功的方式相同的方式成功执行。

python-3.x azure-functions azure-data-factory
1个回答
0
投票

在这里,在 init.py 中,我刚刚获取了这些值并打印并作为函数应用程序的响应发送:

import logging as ri
import azure.functions as func


def main(req: func.HttpRequest) -> func.HttpResponse:
    ri.info('Hello Bojja')
    test = req.params.get('tst')
    ting = req.params.get('ting')
    jing = req.params.get('jing')
    test = f"First Param is {test}, Second Param is {ting}, Third Param is{jing}" 
    return func.HttpResponse(f"Hello Rithwik, {test}")

通话功能:

在 adf 中的函数名称中使用:

HttpTrigger1?tst=rithwik&ting=bojja&jing=chotu
直接发送参数。

enter image description here

HttpTrigger1 是函数名称。

输出:

enter image description here

或者,如果您想使用 url 参数:

在这里,我在 function.json 中使用了路线,如下所示,我给出了类似

test/{test}/{ting}/{jing}
:

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "route": "test/{test}/{ting}/{jing}",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "$return"
    }
  ]
}

在这里,在 init.py 中,我刚刚获取了这些值并打印并作为函数应用程序的响应发送:

import logging as ri
import azure.functions as func


def main(req: func.HttpRequest) -> func.HttpResponse:
    ri.info('Hello Bojja')
    test = req.route_params.get('test')
    ting = req.route_params.get('ting')
    jing = req.route_params.get('jing')
    test = f"First Param is {test}, Second Param is {ting}, Third Param is{jing}" 
    return func.HttpResponse(f"Hello Rithwik, {test}")

通话功能:

在 adf 中的函数名称中使用:

test/rithwik/bojja/chotu
直接发送参数。

enter image description here

输出:

enter image description here

因此,在 function.json 中进行更改并使用 cotrrect url 来调用它。我的函数名称是 Httptrigger1 但当您使用上面的路由时不需要使用它。

© www.soinside.com 2019 - 2024. All rights reserved.