Updated on 2023-11-07 GMT+08:00

Node.js SDK

A synchronous function execution SDK is used as an example. To use the sample code, you must add the SDK dependency with the same language.

Table 1 Node.js SDK information

SDK Info

Description

Version

3.0.47

Installation

npm i @huaweicloud/huaweicloud-sdk-functiongraph

Links

SDK Dependency

Node.js SDK User Guide

The request/response parameters and example requests/responses of the SDK are the same as those of the corresponding APIs. For details about the parameters and examples, see the API for executing a function synchronously.

SDK Request Example

const core = require('@huaweicloud/huaweicloud-sdk-core');
const functiongraph = require("@huaweicloud/huaweicloud-sdk-functiongraph");
// This example is only used for testing purposes. Do not hardcode your AK/SK in the production environment.
const ak = "<YOUR AK>";
const sk = "<YOUR SK>";
const endpoint = "https://functiongraph.<region>.myhuaweicloud.com";
const project_id = "<project_id>";
 
const credentials = new core.BasicCredentials()
                     .withAk(ak)
                     .withSk(sk)
                     .withProjectId(project_id)
const client = functiongraph.FunctionGraphClient.newBuilder()
                            .withCredential(credentials)
                            .withEndpoint(endpoint)
                            .build();
const request = new functiongraph.InvokeFunctionRequest();
request.functionUrn = "urn:fss:<region>:<project_id>:function:default:<func_name>:<version>";
const result = client.invokeFunction(request);
result.then(result => {
    console.log("JSON.stringify(result)::" + JSON.stringify(result));
}).catch(ex => {
    console.log("exception:" + JSON.stringify(ex));
});

Obtain AK/SK, region (endpoint), and project_id by referring to AK/SK Signing and Authentication Guide.

Obtain func_name and version from the function details page.

X-CFF-Request-Version indicates the response body format. v0: text format; v1: JSON format. Select this format when using an SDK.