Cloud function
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
Functional cloud hosting can also pass parameters. After inputting the type:'cloudrun' parameter, it will invoke the functional cloud hosting service.
3. Output Parameters
4. Example code
- Basic SCF Function Call
- Functional cloud hosting call
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
});
import cloudbase from "@cloudbase/js-sdk";
// Initialize SDK instance
const app = cloudbase.init({
env: "xxxx-yyy",
});
app
.callFunction({
name: "test",
// Functional cloud hosting parameter
type: "cloudrun",
method: "POST",
path: "/abc",
data: {
key1: "test value 1",
key2: "test value 2",
},
})
.then((res) => {
const result = res.result; //SCF execution result
});
Node.js Utility Methods
The following methods are only available in Node.js environments.
sendTemplateNotification
app.sendTemplateNotification(params: object, opts?: object): Promise<object>
Sends a template notification.
- The notification policy must be pre-configured in CloudBase Console / Notification Management
- Set the trigger method to "Manual Trigger"
参数
返回
示例
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).
参数
The context parameter of a Cloud Function entry function