函数工作流 FUNCTIONGRAPH-示例3:函数互调:步骤二:创建父函数

时间:2025-05-28 09:46:56

步骤二:创建父函数

  1. 在函数控制台创建父函数。委托名称选择包含“FunctionGraph Administrator”或“Tenant Administrator”权限的委托,本例所选参数如图2所示,可自行选择函数所在区域,其他参数保持默认。
    图2 配置参数
  2. 在“代码”页签,复制以下示例代码到代码编辑区,替换字段后单击“部署代码”。字段说明请参考表1
    import json
    import requests
    def handler (event, context):
        token = context.getToken()
        project_id = context.getProjectID()
        urn = 'urn:fss:xx-xxxxx-x:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:function:xxx:subfunction:latest'  #子函数的urn,在子函数详情页拓扑图的右侧可查询
        url = 'https://functiongraph.{region_id}.{external_global_domain_name}/v2/%s/fgs/functions/%s/invocations' % (project_id,urn) 
        headers = {
            "x-auth-token": token,
            "content-type": 'application/json'
        }
        body = {"k":"v"}
        resp = requests.post(url, json=body, headers=headers, verify=False)
        print(resp.text)
        return {
            "statusCode": 200,
            "isBase64Encoded": False,
            "body": json.dumps(event),
            "headers": {
                "Content-Type": "application/json"
            }
        }
    表1 示例代码字段获取说明

    字段

    说明

    region_id

    区域ID。

    请参考区域和终端节点中“区域”列,根据函数所在区域填写。以“华东-上海一”为例,则填写“cn-east-3”。

    external_global_domain_name

    外部全局 域名

    请填写“myhuaweicloud.com”。

support.huaweicloud.com/api-functiongraph/functiongraph_06_1701.html