Diese Seite ist in Ihrer lokalen Sprache noch nicht verfügbar. Wir arbeiten daran, weitere Sprachversionen hinzuzufügen. Vielen Dank für Ihre Unterstützung.

On this page

Show all

Node.js SDK

Updated on 2024-12-06 GMT+08:00

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

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)
                     .withSecurityToken(securityToken)
                     .withProjectId(projectId)
const client = functiongraph.FunctionGraphClient.newBuilder()
                            .withCredential(credentials)
                            .withEndpoint(endpoint)
                            .build();
const request = new functiongraph.InvokeFunctionRequest();
request.xCffLogType = "tail";
request.xCFFRequestVersion = "v1";
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));
});
NOTE:

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.

xCFFRequestVersionRequest indicates the response body format. v0: text format; v1: JSON format. Select this format when using an SDK.

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback