Skip to main content

Cloud function

Note

When calling cloud storage-related APIs, version v3 uses the open capability of cloud function HTTP API. Before using, please go to cloud Development Platform/identity Authentication/Permission control Verify that the policy management configuration for FunctionsHttpApiAllow is as expected. For more information, see Policy Management Documentation.

callFunction

callFunction<T = any>(object: Object): Promise<Result<ICallFunctionResponse<T>>>

1. API Description

API feature: Execute SCF

2. Input Parameters

object
Object

Functional cloud hosting can also pass parameters. After inputting the type:'cloudrun' parameter, it will invoke the functional cloud hosting service.

object
Object

3. Output Parameters

Promise
Object

4. Example code

import cloudbase from "@cloudbase/js-sdk";
// Initialize SDK instance
const app = cloudbase.init({
env: "xxxx-yyy",
});

app
.callFunction({
name: "test",
data: { a: 1 },
})
.then((res) => {
const result = res.result; //SCF execution result
});

Node.js Utility Methods

Node.js only

The following methods are only available in Node.js environments.

sendTemplateNotification

app.sendTemplateNotification(params: object, opts?: object): Promise<object>

Sends a template notification.

参数

params
Object
opts
Object

返回

Promise
Object

示例


parseContext

app.parseContext(context: object): object

Parses the context parameter of a Cloud Function entry function, converting runtime environment variables into a structured object.

  • Only available inside a Cloud Function environment

Cloud Functions are subject to instance reuse: different invocation sources may write different runtime environment variables (for example, Mini Program invocations set openId and appId, while Web/HTTP invocations do not). When an instance is reused by a subsequent invocation, these environment variables may linger in the process. Therefore, do not read dynamic information such as user identity via process.env or cloud.getWXContext(); always parse it from context using parseContext(context).

参数

context
object

The context parameter of a Cloud Function entry function

返回

Return value
Object

示例