def invoke_function(oci_cfg, compartment_id, name, content): """ Invoke a Function! :param compartment_id: The compartment_id in of the Function. :type compartment_id: str :param name: The Function name. :type name: str :param content: The data to send when invoking the Function. :type content: str """ fn_management_client = functions.FunctionsManagementClient(oci_cfg) print("invoke_function") app = get_unique_application_by_name(fn_management_client, compartment_id, application_name(name)) fn = get_unique_function_by_name(fn_management_client, app.id, function_name(name)) # 8. Create an invocation client and invoke the Function! invoke_client = functions.FunctionsInvokeClient( oci_cfg, service_endpoint=fn.invoke_endpoint) resp = invoke_client.invoke_function(fn.id, invoke_function_body=content) print(resp.data.text)
"<function-name> <request payload>") compartment_name = sys.argv[1] app_name = sys.argv[2] fn_name = sys.argv[3] cfg = config.from_file(file_location=os.getenv("OCI_CONFIG_PATH", config.DEFAULT_LOCATION), profile_name=os.getenv("OCI_CONFIG_PROFILE", config.DEFAULT_PROFILE)) if int(os.getenv("DEBUG", "0")) > 0: requests_log = logging.getLogger("requests.packages.urllib3") requests_log.setLevel(logging.DEBUG) requests_log.propagate = True cfg.update({"log_requests": True}) functions_client = functions.FunctionsManagementClient(cfg) config.validate_config(cfg) compartment = get_compartment(cfg, compartment_name) app = get_app(functions_client, app_name, compartment) fn = get_function(functions_client, app, fn_name) invoke_client = functions.FunctionsInvokeClient( cfg, service_endpoint=fn.invoke_endpoint) resp = invoke_client.invoke_function(fn.id, sys.argv[4]) print(resp.data.text)