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

时间:2023-11-01 16:25:44

步骤二:创建父函数

  1. 在控制台创建父函数。委托名称选择包含“FunctionGraph Administrator”或“Tenant Administrator”权限的委托,本例所选参数如图2所示,其他参数保持默认。
    图2 配置参数
  2. 在“代码”页签,进行代码编辑,示例代码如下所示。
    import jsonimport requestsdef 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.xx-xxxxx-x.xxxxxxxxxxxxx.com/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"        }    }
support.huaweicloud.com/api-functiongraph/functiongraph_06_1701.html