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.
SDK Info |
Description |
---|---|
Installation |
npm i @huaweicloud/huaweicloud-sdk-functiongraph |
Links |
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)); });
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
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.