Cloud Functions
listFunctions
1. Interface Description
Function: Get cloud function list
Declaration: listFunctions(limit, offset): Promise<Object>
| Field | Required | Type | Description |
|---|
| limit | No | Number | Range |
| offset | No | Number | Offset |
3. Return Result
| Field | Required | Type | Description |
|---|
| RequestID | Yes | String | Request unique ID |
| TotalCount | Yes | Number | Total count |
| Functions | Yes | Array | Function list |
| Functions[].FunctionId | Yes | String | Function ID |
| Functions[].FunctionName | Yes | String | Function name |
| Functions[].Namespace | Yes | String | Namespace |
| Functions[].Runtime | Yes | String | Runtime |
| Functions[].AddTime | Yes | String | Creation time |
| Functions[].ModTime | Yes | String | Modification time |
4. Sample Code
import CloudBase from '@cloudbase/manager-node'
const { functions } = new CloudBase({
secretId: 'Your SecretId',
secretKey: 'Your SecretKey',
envId: 'Your envId'
})
async function test() {
let res = await functions.listFunctions(20, 0)
const { Functions } = res
for(let function in Functions) {
console.log(function)
}
}
test()
getFunctionList
1. Interface Description
Function: Get cloud function list
Declaration: getFunctionList(limit, offset): Promise<Object>
Supported since version 3.7.0
| Field | Required | Type | Description |
|---|
| limit | No | Number | Range |
| offset | No | Number | Offset |
3. Return Result
| Field | Required | Type | Description |
|---|
| RequestID | Yes | String | Request unique ID |
| TotalCount | Yes | Number | Total count |
| Functions | Yes | Array | Function list |
| Functions[].FunctionId | Yes | String | Function ID |
| Functions[].FunctionName | Yes | String | Function name |
| Functions[].Namespace | Yes | String | Namespace |
| Functions[].Runtime | Yes | String | Runtime |
| Functions[].AddTime | Yes | String | Creation time |
| Functions[].ModTime | Yes | String | Modification time |
| Functions[].Status | Yes | String | Function status |
| Functions[].StatusDesc | Yes | String | Status description |
| Functions[].Description | Yes | String | Function description |
4. Sample Code
import CloudBase from '@cloudbase/manager-node'
const { functions } = new CloudBase({
secretId: 'Your SecretId',
secretKey: 'Your SecretKey',
envId: 'Your envId'
})
async function test() {
let res = await functions.getFunctionList(20, 0)
const { Functions } = res
for(let function in Functions) {
console.log(function)
}
}
test()
createFunction
1. Interface Description
Function: Create function
Declaration: createFunction(funcParam: ICreateFunctionParam): Promise<Object>
⚠️ From version 2.0.0, request parameters changed from ( func: ICloudFunction, functionRootPath: string, force: boolean, base64Code: string ) to (funcParam: ICreateFunctionParam), which is a breaking change
ICreateFunctionParam
| Field | Required | Type | Description |
|---|
| func | Yes | ICloudFunction | Function configuration |
| functionRootPath | No | String | Local function file directory |
| force | No | Boolean | Whether to overwrite same-name function, defaults to false |
| base64Code | No | String | Base64 encoded function file |
| codeSecret | No | String | Code protection key |
| functionPath | No | String | Function folder path |
| deployMode | No | String | Upload method: cos or zip, defaults to cos (zip limited to 1.5MB) |
💡 Upload Method: Defaults to cos. Use zip if needed (limited to 1.5MB).
Note: To update function code only, use the updateFunctionCode interface.
Note: If a function with the same name exists and force is set to true, the SDK will automatically update function code, configuration, and create triggers.
Note: createFunction supports multiple ways to create functions:
- Directly specify the function folder path
- Specify the local function folder root directory
functionRootPath, determine function file path by functionRootPath + name - Compress function code package to zip file, base64 encode it, and pass to base64Code parameter
Note: ICloudFunctionConfig is the legacy parameter structure
ICloudFunctionConfig
| Field | Required | Type | Description |
|---|
| timeout | No | Number | Function timeout |
| envVariables | No | Object | Object containing environment variable key-value pairs |
| vpc | No | IFunctionVPC | VPC configuration |
| runtime | No | String | Runtime configuration. Options: Nodejs20.19, Nodejs18.15, Nodejs16.13, Nodejs14.18, Nodejs12.16, Nodejs10.15, Php8.0, Php7.4, Php7.2, Python3.9, Python3.7, Python3.6, Python2.7, Golang1, Java8 |
| installDependency | No | Boolean | Whether to install dependencies, Node.js only |
ICloudFunction
| Field | Required | Type | Description |
|---|
| name | Yes | String | Function name |
| description | No | String | Function description |
| type | No | String | Function type: Event (default) or HTTP |
| timeout | No | Number | Function timeout |
| envVariables | No | Object | Object containing environment variable key-value pairs |
| vpc | No | IFunctionVPC | VPC configuration |
| runtime | No | String | Runtime configuration. Options: Nodejs20.19, Nodejs18.15, Nodejs16.13, Nodejs14.18, Nodejs12.16, Nodejs10.15, Php8.0, Php7.4, Php7.2, Python3.9, Python3.7, Python3.6, Python2.7, Golang1, Java8 |
| installDependency | No | Boolean | Whether to install dependencies, Node.js only |
| triggers | No | Array of ICloudFunctionTrigger | |
| handler | No | String | Function entry point |
| ignore | No | String or Array<String> | Files to ignore when uploading, using Glob patterns |
| isWaitInstall | No | Boolean | Whether to wait for dependency installation to complete |
| layers | No | Array<ILayerItem> | Layer version list to associate, layers override in order |
ILayerItem
| Field | Required | Type | Description |
|---|
| name | Yes | String | Layer name |
| version | Yes | Number | Version number |
Note: handler is the function entry point. Node.js projects default to index.main. Entry file can only be in root directory, e.g., Node.js project's index.main points to the main method in index.js file
Note: For cloud dependency installation, Node.js runtime needs to be set to a supported version like Nodejs18.15, and package.json must be in the same directory as the entry file. Cloud dependency installation currently does not support other runtimes
If not using cloud dependency installation, Node.js runtime does not need runtime (defaults to Nodejs18.15), but Php and Java must specify runtime.
ICloudFunctionTrigger
| Field | Required | Type | Description |
|---|
| name | Yes | String | Trigger name |
| type | Yes | String | Trigger type. Options: timer |
| config | Yes | String | Trigger configuration. For timer triggers, config is a cron expression |
IFunctionVPC
| Field | Required | Type | Description |
|---|
| vpcId | Yes | String | VPC Id |
| subnetId | Yes | String | VPC Subnet Id |
⚠️ Please verify function creation and deployment success in the CloudBase console during testing. It's possible that creation succeeds (createFunction returns successfully) but deployment fails. Deployment failure is usually due to handler parameter not matching the source code package.
3. Return Result
| Field | Required | Type | Description |
|---|
| RequestId | Yes | String | Request ID |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { functions } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});
async function test() {
await functions.createFunction({
func: {
name: "app",
timeout: 5,
envVariables: {
key: "value",
akey: "c",
},
runtime: "Nodejs18.15",
triggers: [
{
name: "myTrigger",
type: "timer",
config: "0 0 2 1 * * *",
},
],
layers: [
{
version: 1,
name: "layerName",
},
],
},
functionRootPath: "",
force: true,
base64Code:
"UEsDBAoAAAAAAOdCBU8AAAAAAAAAAAAAAAAFAAAAZGlzdC9QSwMEFAAIAAgAkhkBTwAAAAAAAAAAAAAAAAgAAABpbmRleC5qc2WNMQrDMBRDd59Cmx0IuUEy9wadXfdTQlT/Yv+UQMndmxZv0ST0kOTXKqhW5mTeOdleWqwOzzhnjAjylmw9kmaT7WcieYtp6TBO+DgcOlhVykB9BH8RUnHVwrvvTvi/do7begPtIeSV7NEqu/sCUEsHCLKdLCxuAAAAqAAAAFBLAwQUAAgACADnQgVPAAAAAAAAAAAAAAAADQAAAGRpc3QvZGlzdC56aXAL8GZm4WIAgedOrP5gBpRgBdIpmcUl+gFAJSIMHEA4SZIRRQkHUElmXkpqhV5WcWqvIddhAxHn8vlOs2U5djoafWebG/s92Cnkf9L/KQ4n784Wy7+o8mXCk+taK8KepdyzvBkXtYbvvEV6D8enaTm2k9Imv01XquzOfGng98NCxioi9JRDLUu9YFDh1UO73/v92F/Wd7uK+a3ik6lvLmrt/s0U4M3OsWmujk4e0AUrgBjhRnRv8MK8AfKLXlVmAQBQSwcITXynOsAAAADyAAAAUEsBAi0DCgAAAAAA50IFTwAAAAAAAAAAAAAAAAUAAAAAAAAAAAAQAO1BAAAAAGRpc3QvUEsBAi0DFAAIAAgAkhkBT7KdLCxuAAAAqAAAAAgAAAAAAAAAAAAgAKSBIwAAAGluZGV4LmpzUEsBAi0DFAAIAAgA50IFT018pzrAAAAA8gAAAA0AAAAAAAAAAAAgAKSBxwAAAGRpc3QvZGlzdC56aXBQSwUGAAAAAAMAAwCkAAAAwgEAAAAA",
});
}
test();
updateFunctionCode
1. Interface Description
Function: Update cloud function code
Declaration: updateFunctionCode(funcParam: IUpdateFunctionCodeParam): Promise<Object>
⚠️ From version 2.0.0, request parameters changed from ( func: ICloudFunction, functionRootPath: string, base64Code: string ) to (funcParam: IUpdateFunctionCodeParam), which is a breaking change
IUpdateFunctionCodeParam
| Field | Required | Type | Description |
|---|
| func | Yes | ICloudFunction | Function configuration |
| functionPath | No | String | Function folder path |
| functionRootPath | No | String | Local function file directory |
| base64Code | No | String | Base64 encoded function file |
| codeSecret | No | String | Code protection key |
| deployMode | No | String | Upload method: cos or zip, defaults to cos (zip limited to 1.5MB) |
💡 Upload Method: Defaults to cos. Use zip if needed (limited to 1.5MB).
ICloudFunction structure
3. Return Result
| Field | Required | Type | Description |
|---|
| RequestId | Yes | String | Request ID |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { functions } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});
async function test() {
let res = await functions.updateFunctionCode({
func: {
name: "app",
},
functionRootPath: "",
base64Code:
"UEsDBAoAAAAAAOdCBU8AAAAAAAAAAAAAAAAFAAAAZGlzdC9QSwMEFAAIAAgAkhkBTwAAAAAAAAAAAAAAAAgAAABpbmRleC5qc2WNMQrDMBRDd59Cmx0IuUEy9wadXfdTQlT/Yv+UQMndmxZv0ST0kOTXKqhW5mTeOdleWqwOzzhnjAjylmw9kmaT7WcieYtp6TBO+DgcOlhVykB9BH8RUnHVwrvvTvi/do7begPtIeSV7NEqu/sCUEsHCLKdLCxuAAAAqAAAAFBLAwQUAAgACADnQgVPAAAAAAAAAAAAAAAADQAAAGRpc3QvZGlzdC56aXAL8GZm4WIAgedOrP5gBpRgBdIpmcUl+gFAJSIMHEA4SZIRRQkHUElmXkpqhV5WcWqvIddhAxHn8vlOs2U5djoafWebG/s92Cnkf9L/KQ4n784Wy7+o8mXCk+taK8KepdyzvBkXtYbvvEV6D8enaTm2k9Imv01XquzOfGng98NCxioi9JRDLUu9YFDh1UO73/v92F/Wd7uK+a3ik6lvLmrt/s0U4M3OsWmujk4e0AUrgBjhRnRv8MK8AfKLXlVmAQBQSwcITXynOsAAAADyAAAAUEsBAi0DCgAAAAAA50IFTwAAAAAAAAAAAAAAAAUAAAAAAAAAAAAQAO1BAAAAAGRpc3QvUEsBAi0DFAAIAAgAkhkBT7KdLCxuAAAAqAAAAAgAAAAAAAAAAAAgAKSBIwAAAGluZGV4LmpzUEsBAi0DFAAIAAgA50IFT018pzrAAAAA8gAAAA0AAAAAAAAAAAAgAKSBxwAAAGRpc3QvZGlzdC56aXBQSwUGAAAAAAMAAwCkAAAAwgEAAAAA",
});
console.log(res);
}
test();
updateFunctionConfig
1. Interface Description
Function: Update cloud function configuration
Declaration: updateFunctionConfig(funcParam: ICloudFunction): Promise<Object>
⚠️ From version 2.0.0, request parameters changed from ( name: string, config: ICloudFunctionConfig ) to (funcParam: ICloudFunction), which is a breaking change
| Field | Required | Type | Description |
|---|
| funcParam | Yes | ICloudFunction | Function configuration |
ICloudFunction structure
3. Return Result
| Field | Required | Type | Description |
|---|
| RequestId | Yes | String | Request ID |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { functions } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});
async function test() {
let res = await functions.updateFunctionConfig({
name: "app",
timeout: 6,
});
console.log(res);
}
test();
deleteFunction
1. Interface Description
Function: Delete cloud function
Declaration: deleteFunction(name: string): Promise<Object>
| Field | Required | Type | Description |
|---|
| name | Yes | String | Function name |
| qualifier | No | String | Version to delete, defaults to deleting all versions |
3. Return Result
| Field | Required | Type | Description |
|---|
| RequestId | Yes | String | Request ID |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { functions } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});
async function test() {
await functions.deleteFunction("functionName", "1");
}
test();
getFunctionDetail
1. Interface Description
Function: Get cloud function details
Declaration: getFunctionDetail(name: string, codeSecret?: string): Promise<Object>
| Field | Required | Type | Description |
|---|
| name | Yes | String | Function name |
| codeSecret | No | String | Code protection key |
3. Return Result
| Field | Required | Type | Description |
|---|
| RequestId | Yes | String | Request unique ID |
| FunctionName | Yes | String | Function name |
| Namespace | Yes | String | Namespace |
| Runtime | Yes | String | Runtime |
| Handler | Yes | String | Function entry point |
| Description | Yes | String | Function description |
| ModTime | Yes | String | Modification time |
| Environment | Yes | Object | Environment variables |
| Environment.Variables | Yes | Array | Environment variable array |
| Environment.Variables[].Key | Yes | String | Variable Key |
| Environment.Variables[].Value | Yes | String | Variable Value |
| MemorySize | Yes | Number | Max available memory |
| Timeout | Yes | Number | Function timeout |
| CodeInfo | Yes | String | Function code |
| Triggers | Yes | Array<ITrigger> | Function trigger list |
ITrigger
| Field | Required | Type | Description |
|---|
| Type | Yes | String | Trigger type |
| TriggerName | Yes | String | Trigger name |
| TriggerDesc | Yes | String | Trigger configuration |
| ModTime | Yes | Timestamp | Last modification time |
| AddTime | Yes | Timestamp | Creation time |
| AvailableStatus | Yes | String | Trigger status |
| Enable | Yes | Number | Enable switch |
| CustomArgument | Yes | String | Custom argument |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { functions } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});
async function test() {
let res = await functions.getFunctionDetail("functionName");
console.log(res);
}
test();
invokeFunction
1. Interface Description
Function: Invoke cloud function
Declaration: invokeFunction(name: string, params: object): Promise<Object>
| Field | Required | Type | Description |
|---|
| functionName | Yes | String | Function name |
| params | No | Object | Optional, user input when invoking |
3. Return Result
| Field | Required | Type | Description |
|---|
| RequestId | Yes | String | Request unique ID |
| FunctionRequestId | Yes | String | This function execution ID |
| Duration | Yes | Number | Execution duration in ms, empty for async invocation |
| BillDuration | Yes | Number | Billing duration in ms, empty for async invocation |
| MemUsage | Yes | Number | Memory usage in Bytes, empty for async invocation |
| InvokeResult | Yes | Number | 0 for success, empty for async invocation |
| RetMsg | Yes | String | Function return value, empty for async invocation |
| ErrMsg | Yes | String | Error message, empty for async invocation |
| Log | Yes | String | Log output during execution, empty for async invocation |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { functions } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});
async function test() {
const res = await functions.invokeFunction("app", {
a: 1,
});
console.log(res.RetMsg);
}
test();
getFunctionLogs
This interface is deprecated
This interface no longer returns specific log details. Please use the requestId returned by this interface to call searchClsLog function to query log details.
1. Interface Description
Function: Get cloud function invocation logs
Declaration: getFunctionLogs(options: IFunctionLogOptions): Promise<Object>
IFunctionLogOptions
| Field | Required | Type | Description |
|---|
| name | Yes | String | Function name |
| offset | No | Number | Data offset, Offset+Limit cannot exceed 10000 |
| limit | No | Number | Return data length, Offset+Limit cannot exceed 10000 |
| order | No | String | Sort order, options: desc, asc |
| orderBy | No | String | Sort field: function_name, duration, mem_usage, start_time |
| startTime | No | String | Query date, e.g., 2017-05-16 20:00:00, within one day of EndTime |
| endTime | No | String | Query date, e.g., 2017-05-16 20:59:59, within one day of StartTime |
| requestId | No | String | RequestId of the function execution |
3. Return Result
| Field | Required | Type | Description |
|---|
| RequestId | Yes | String | Request unique ID |
| TotalCount | Yes | String | Total function logs |
| Data[] | Yes | Array | Function execution results |
| Data[].RequestId | Yes | String | RequestId of the function execution |
| Data[].FunctionName | Yes | String | Function name |
| Data[].RetCode | Yes | Number | Execution result, 0 for success, other values for failure |
| Data[].InvokeFinished | Yes | Number | 1 for finished, other values for exception |
| Data[].StartTime | Yes | String | Function start execution time |
| Data[].Duration | Yes | Number | Execution duration in ms, empty for async invocation |
| Data[].BillDuration | Yes | Number | Billing duration in ms, empty for async invocation |
| Data[].MemUsage | Yes | Number | Memory usage in Bytes, empty for async invocation |
| Data[].RetMsg | Yes | String | Function return value, empty for async invocation |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const manager = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});
const { functions } = manager;
async function test() {
const logs = await functions.getFunctionLogs({ name: "app" });
const { Data } = logs;
for (let item in Data) {
console.log(item.RequestId);
const clsLogRes = await manager.commonService().call({
Action: "SearchClsLog",
Param: {
EnvId: cloudBaseConfig.envId,
StartTime: "2021-06-11 11:06:20",
EndTime: "2021-06-30 11:06:20",
Limit: 100,
Sort: "asc",
QueryString: `requestId:${item.RequestId}`,
},
});
console.log("clsLogRes", clsLogRes);
}
}
test();
getFunctionLogsV2
This interface does not return specific log details. Please use the RequestId from each log in the LogList array to call getFunctionLogDetail function to query log details.
1. Interface Description
Function: Get cloud function invocation log list
Declaration: getFunctionLogsV2(options: IFunctionLogOptionsV2): Promise<Object>
IFunctionLogOptionsV2
| Field | Required | Type | Description |
|---|
| name | Yes | String | Function name |
| offset | No | Number | Data offset, Offset+Limit cannot exceed 10000 |
| limit | No | Number | Return data length, Offset+Limit cannot exceed 10000 |
| startTime | No | String | Query date, e.g., 2017-05-16 20:00:00, within one day of EndTime |
| endTime | No | String | Query date, e.g., 2017-05-16 20:59:59, within one day of StartTime |
| requestId | No | String | RequestId of the function execution |
| qualifier | No | String | Function version, defaults to $LATEST |
3. Return Result
| Field | Required | Type | Description |
|---|
| RequestId | Yes | String | Request unique ID |
| LogList[] | Yes | Array | Function execution results |
| Data[].RequestId | Yes | String | Function log request ID |
| Data[].RetryNum | Yes | String | Function log retry ID |
| Data[].RetCode | Yes | Number | Execution status code, 200/500 |
| Data[].StartTime | Yes | String | Function log start time |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const manager = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});
const { functions } = manager;
async function test() {
const logs = await functions.getFunctionLogs({
name: "app",
startTime: "2025-07-19 09:00:00",
endTime: "2025-07-19 19:00:00",
});
const { LogList } = logs;
for (let item in LogList) {
logId = item.RequestId;
const logDetail = await functions.getFunctionLogDetail({
startTime: "2025-07-19 09:00:00",
logRequestId: logId,
endTime: "2025-07-19 19:00:00",
});
}
}
test();
getFunctionLogDetail
1. Interface Description
Function: Query log details based on log requestId returned by getFunctionLogsV2
Declaration: getFunctionLogDetail(options: IFunctionLogDetailOptions): Promise<Object>
IFunctionLogDetailOptions
| Field | Required | Type | Description |
|---|
| startTime | No | String | Query date, e.g., 2017-05-16 20:00:00, within one day of EndTime |
| endTime | No | String | Query date, e.g., 2017-05-16 20:59:59, within one day of StartTime |
| requestId | No | String | RequestId of the function execution |
3. Return Result
| Field | Required | Type | Description |
|---|
| StartTime | No | String | Invocation time |
| Duration | No | Number | Duration |
| MemUsage | No | Number | Memory usage |
| LogJson | No | String | Log content |
| ListOver | No | Boolean | Pagination flag |
| Context | No | String | Pagination cursor |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const manager = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});
const { functions } = manager;
async function test() {
const logs = await functions.getFunctionLogs({
name: "app",
startTime: "2025-07-19 09:00:00",
endTime: "2025-07-19 19:00:00",
});
const { LogList } = logs;
for (let item in LogList) {
logId = item.RequestId;
const logDetail = await functions.getFunctionLogDetail({
startTime: "2025-07-19 09:00:00",
logRequestId: logId,
endTime: "2025-07-19 19:00:00",
});
}
}
test();
copyFunction
1. Interface Description
Function: Copy cloud function
Declaration: copyFunction(name, newFunctionName, targetEnvId, force): Promise<Object>
| Field | Required | Type | Description |
|---|
| name | Yes | String | Original function name |
| newFunctionName | Yes | String | New function name |
| targetEnvId | Yes | String | Target environment ID (for cross-env copy) |
| force | No | Boolean | Whether to overwrite same-name function |
3. Return Result
| Field | Required | Type | Description |
|---|
| RequestId | Yes | String | Request ID |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { functions } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});
async function test() {
await functions.copyFunction();
}
test();
createFunctionTriggers
1. Interface Description
Function: Create cloud function triggers
Declaration: createFunctionTriggers(name: string, triggers: ICloudFunctionTrigger[]): Promise<Object>
| Field | Required | Type | Description |
|---|
| name | Yes | String | Function name |
| triggers | Yes | ICloudFunctionTrigger | Trigger config array |
3. Return Result
| Field | Required | Type | Description |
|---|
| RequestId | Yes | String | Request ID |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { functions } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});
async function test() {
await functions.createFunctionTriggers("app", [
{
name: "newTrigger",
type: "timer",
config: "0 0 2 1 * * *",
},
]);
}
test();
deleteFunctionTrigger
1. Interface Description
Function: Delete cloud function trigger
Declaration: deleteFunctionTrigger(name: string, triggerName: string): Promise<Object>
| Field | Required | Type | Description |
|---|
| name | Yes | String | Function name |
| triggerName | Yes | String | Trigger name |
3. Return Result
| Field | Required | Type | Description |
|---|
| RequestId | Yes | String | Request ID |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { functions } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});
async function test() {
await functions.deleteFunctionTrigger("app", "newTrigger");
}
test();
getFunctionDownloadUrl
1. Interface Description
Function: Get cloud function code download URL
Declaration: getFunctionDownloadUrl(functionName:string, codeSecret?: string): Promise<Object>
| Field | Required | Type | Description |
|---|
| functionName | Yes | String | Function name |
| codeSecret | No | String | Code protection key |
3. Return Result
| Field | Required | Type | Description |
|---|
| RequestID | Yes | String | Request unique ID |
| Url | Yes | String | Function code download URL |
| CodeSha256 | Yes | String | Function SHA256 hash |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { functions } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});
async function test() {
const res = await functions.getFunctionDownloadUrl("sum");
const { Url } = res;
console.log(Url);
}
test();
updateFunctionIncrementalCode
1. Interface Description
Function: Incrementally upload cloud function code
Declaration: updateFunctionIncrementalCode(funcParam: IUpdateFunctionIncrementalCodeParam): Promise<Object>
| Field | Required | Type | Description |
|---|
| funcParam | Yes | IUpdateFunctionIncrementalCodeParam struct | Incremental update item |
IUpdateFunctionIncrementalCodeParam struct
| Field | Required | Type | Description |
|---|
| func | Yes | ICloudFunction | Function config, only name and runTime fields supported for incremental update |
| functionRootPath | Yes | String | Local function file directory |
| deleteFiles | No | Array<String> | Files/directories to delete, use relative paths, directories must end with / |
| addFiles | No | String | Glob pattern for files/directories to add or modify, supports single file or folder |
⚠️ Note the path difference between Linux and Windows ('/' vs '\')
⚠️ Incrementally updating package.json does not trigger dependency installation
3. Return Result
| Field | Required | Type | Description |
|---|
| RequestId | Yes | String | Request ID |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { functions } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});
async function test() {
await functions.updateFunctionIncrementalCode({
func: {
name: "sum",
runTime: "Nodejs18.15",
},
addFiles: "test/index.js",
});
await functions.updateFunctionIncrementalCode({
func: {
name: "sum",
runTime: "Nodejs18.15",
},
addFiles: "test/*",
});
await functions.updateFunctionIncrementalCode({
func: {
name: "sum",
runTime: "Nodejs18.15",
},
deleteFiles: ["test/index.js"],
});
await functions.updateFunctionIncrementalCode({
func: {
name: "sum",
runTime: "Nodejs18.15",
},
deleteFiles: ["test/"],
});
}
test();
createLayer
1. Interface Description
Function: Publish layer version
Declaration: createLayer(options: IFunctionLayerOptions): Promise<Object>
| Field | Required | Type | Description |
|---|
| options | Yes | IFunctionLayerOptions struct | Request item |
IFunctionLayerOptions struct
| Field | Required | Type | Description |
|---|
| contentPath | No | String | Folder or ZIP file path |
| base64Content | No | String | Base64 encoded file |
| name | Yes | String | Layer name, 1-64 chars, alphanumeric with - and , must start with letter, cannot end with - or |
| runtimes | Yes | Array<String> | Compatible runtimes, multiple allowed, corresponds to function Runtime options |
| description | No | String | Layer version description |
| licenseInfo | No | String | Layer software license |
3. Return Result
| Field | Required | Type | Description |
|---|
| RequestId | Yes | String | Request ID |
| LayerVersion | Yes | Number | Layer version |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { functions } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});
async function test() {
const res = await functions.createLayer({
name: layerName,
contentPath: "./test/functions/luke/",
runtimes: ["Nodejs18.15"],
});
console.log(res.LayerVersion);
}
test();
deleteLayerVersion
1. Interface Description
Function: Delete layer version
Declaration: deleteLayerVersion(options: ILayerOptions): Promise<Object>
| Field | Required | Type | Description |
|---|
| options | Yes | ILayerOptions struct | Request item |
ILayerOptions struct
| Field | Required | Type | Description |
|---|
| name | Yes | String | Layer name |
| version | Yes | Number | Version number |
3. Return Result
| Field | Required | Type | Description |
|---|
| RequestId | Yes | String | Request ID |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { functions } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});
async function test() {
const res = await functions.deleteLayerVersion({
name: layerName,
version: 1,
});
console.log(res.RequestId);
}
test();
listLayerVersions
1. Interface Description
Function: Get layer version list
Declaration: listLayerVersions(options: IVersionListOptions): Promise<Object>
| Field | Required | Type | Description |
|---|
| options | Yes | IVersionListOptions struct | Request item |
IVersionListOptions struct
| Field | Required | Type | Description |
|---|
| name | Yes | String | Layer name |
| runtimes | No | Array<String> | Version number |
3. Return Result
| Field | Required | Type | Description |
|---|
| RequestId | Yes | String | Request ID |
| LayerVersions | Yes | Array<ILayerVersionInfo> | Layer details |
ILayerVersionInfo struct
| Field | Required | Type | Description |
|---|
| CompatibleRuntimes | Yes | Array<String> | Compatible runtimes |
| AddTime | Yes | String | Creation time |
| Description | Yes | String | Version description |
| LicenseInfo | Yes | String | License info |
| LayerVersion | Yes | Number | Version number |
| LayerName | Yes | String | Layer name |
| Status | Yes | String | Layer status: Active, Publishing, PublishFailed, Deleted |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { functions } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});
async function test() {
const res = await functions.listLayerVersions({
name: layerName,
});
console.log(res.LayerVersions);
}
test();
listLayers
1. Interface Description
Function: Get layer list
Declaration: listLayers(options: ILayerListOptions): Promise<Object>
| Field | Required | Type | Description |
|---|
| options | Yes | ILayerListOptions struct | Request item |
ILayerListOptions struct
| Field | Required | Type | Description |
|---|
| offset | No | Number | Offset |
| limit | No | Number | Limit |
| runtime | No | String | Compatible runtime |
| searchKey | No | String | Search key, fuzzy match |
3. Return Result
| Field | Required | Type | Description |
|---|
| RequestId | Yes | String | Request ID |
| TotalCount | Yes | Number | Total layers |
| Layers | Yes | Array<ILayerVersionInfo> | Layer details |
ILayerVersionInfo struct
| Field | Required | Type | Description |
|---|
| CompatibleRuntimes | Yes | Array<String> | Compatible runtimes |
| AddTime | Yes | String | Creation time |
| Description | Yes | String | Version description |
| LicenseInfo | Yes | String | License info |
| LayerVersion | Yes | Number | Version number |
| LayerName | Yes | String | Layer name |
| Status | Yes | String | Layer status: Active, Publishing, PublishFailed, Deleted |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { functions } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});
async function test() {
const res = await functions.listLayers({});
console.log(res.Layers);
}
test();
getLayerVersion
1. Interface Description
Function: Get layer version details
Declaration: getLayerVersion(options: ILayerOptions): Promise<Object>
| Field | Required | Type | Description |
|---|
| options | Yes | ILayerOptions struct | Request item |
ILayerOptions struct
| Field | Required | Type | Description |
|---|
| name | Yes | String | Layer name |
| version | Yes | Number | Version number |
3. Return Result
| Field | Required | Type | Description |
|---|
| RequestId | Yes | String | Request ID |
| CompatibleRuntimes | Yes | Array<String> | Compatible runtimes |
| CodeSha256 | Yes | String | Layer version file SHA256 |
| Location | Yes | String | Layer version file download URL |
| AddTime | Yes | String | Version creation time |
| Description | Yes | String | Version description |
| LicenseInfo | Yes | String | License info |
| LayerVersion | Yes | Number | Version number |
| LayerName | Yes | String | Layer name |
| Status | Yes | String | Layer status: Active, Publishing, PublishFailed, Deleted |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { functions } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});
async function test() {
const res = await functions.getLayerVersion({ name: layerName, version: 2 });
console.log(res.LayerVersion);
}
test();
setProvisionedConcurrencyConfig
1. Interface Description
Function: Set function provisioned concurrency
Declaration: setProvisionedConcurrencyConfig(options: ISetProvisionedConcurrencyConfig): Promise<Object>
ISetProvisionedConcurrencyConfig struct
| Field | Required | Type | Description |
|---|
| functionName | Yes | String | Function name |
| qualifier | Yes | String | Function version name |
| versionProvisionedConcurrencyNum | Yes | Number | Provisioned concurrency for version |
3. Return Result
| Field | Required | Type | Description |
|---|
| RequestId | Yes | String | Request ID |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { functions } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});
async function test() {
const setProvisionedConcurrencyConfigRes =
await functions.setProvisionedConcurrencyConfig({
functionName: "sum",
qualifier: "1",
versionProvisionedConcurrencyNum: 10,
});
console.log(setProvisionedConcurrencyConfigRes);
}
test();
getProvisionedConcurrencyConfig
1. Interface Description
Function: Query function provisioned concurrency
Declaration: getProvisionedConcurrencyConfig(options: IGetProvisionedConcurrencyConfig): Promise<Object>
IGetProvisionedConcurrencyConfig struct
| Field | Required | Type | Description |
|---|
| functionName | Yes | String | Function name |
| qualifier | No | String | Function version, queries all versions if not specified |
3. Return Result
| Field | Type | Description |
|---|
| RequestId | String | Request ID |
| UnallocatedConcurrencyNum | Number | Remaining configurable provisioned concurrency |
| Allocated | Array<IVersionProvisionedConcurrencyInfo> | Provisioned concurrency config details |
IVersionProvisionedConcurrencyInfo
| Field | Type | Description |
|---|
| AllocatedProvisionedConcurrencyNum | Number | Configured provisioned concurrency |
| AvailableProvisionedConcurrencyNum | Number | Completed provisioned concurrency |
| Status | String | Task status: Done, InProgress, Failed |
| StatusReason | String | Status description |
| Qualifier | String | Version number |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { functions } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});
async function test() {
const getProvisionedConcurrencyConfigRes =
await functions.getProvisionedConcurrencyConfig({
functionName: "sum",
qualifier: "1",
});
console.log(getProvisionedConcurrencyConfigRes);
}
test();
deleteProvisionedConcurrencyConfig
1. Interface Description
Function: Delete function provisioned concurrency
Declaration: deleteProvisionedConcurrencyConfig(options: IDeleteProvisionedConcurrencyConfig): Promise<Object>
IDeleteProvisionedConcurrencyConfig struct
| Field | Required | Type | Description |
|---|
| functionName | Yes | String | Function name |
| qualifier | Yes | String | Function version, queries all versions if not specified |
3. Return Result
| Field | Type | Description |
|---|
| RequestId | String | Request ID |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { functions } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});
async function test() {
const deleteProvisionedConcurrencyConfigRes =
await functions.deleteProvisionedConcurrencyConfig({
functionName: "sum",
qualifier: "1",
});
console.log(deleteProvisionedConcurrencyConfigRes);
}
test();
publishVersion
1. Interface Description
Function: Publish new function version
Declaration: publishVersion(options: IPublishVersionParams): Promise<Object>
IPublishVersionParams struct
| Field | Required | Type | Description |
|---|
| functionName | Yes | String | Function name |
| description | No | String | Version description |
3. Return Result
| Field | Type | Description |
|---|
| RequestId | String | Request ID |
| FunctionVersion | String | Function version |
| CodeSize | Number | Code size |
| MemorySize | Number | Max available memory |
| Handler | String | Function entry |
| Timeout | Number | Function timeout |
| Runtime | String | Runtime environment |
| Namespace | String | Function namespace |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { functions } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});
async function test() {
const createNewVersionRes = await functions.publishVersion({
functionName: "sum",
description: "test",
});
console.log(createNewVersionRes);
}
test();
listVersionByFunction
1. Interface Description
Function: Query function version list
Declaration: listVersionByFunction(options: IListFunctionVersionParams): Promise<Object>
IListFunctionVersionParams struct
| Field | Required | Type | Description |
|---|
| functionName | Yes | String | Function name |
| offset | No | Number | Data offset, default 0 |
| limit | No | Number | Return data length, default 20 |
| order | No | Number | Sort order: ASC or DESC |
| orderBy | No | Number | Sort field: AddTime, ModTime |
3. Return Result
| Field | Type | Description |
|---|
| RequestId | String | Request ID |
| TotalCount | String | Total function versions |
| FunctionVersion | Array<String> | Function version names |
| Versions | Array<IFunctionVersion> | Function version list |
IFunctionVersion
| Field | Type | Description |
|---|
| Version | String | Function version name |
| Description | String | Version description |
| AddTime | String | Creation time |
| ModTime | String | Modification time |
| Status | String | Version status |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { functions } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});
async function test() {
const functionVersions = await functions.listVersionByFunction({
functionName: "sum",
});
console.log(functionVersions);
}
test();
updateFunctionAliasConfig
1. Interface Description
Function: Update function version configuration (alias configuration)
Declaration: updateFunctionAliasConfig(options: IUpdateFunctionAliasConfig): Promise<Object>
IUpdateFunctionAliasConfig struct
| Field | Required | Type | Description |
|---|
| functionName | Yes | String | Function name |
| name | Yes | String | Alias name, default '$DEFAULT' |
| functionVersion | Yes | String | Alias main version, default '$LATEST' |
| description | No | String | Alias description |
| routingConfig | No | IRoutingConfig | Routing configuration |
IRoutingConfig
| Field | Required | Type | Description |
|---|
| AddtionVersionMatchs | Yes | Array<IVersionMatch> | Rule routing extra versions |
IVersionMatch
| Field | Required | Type | Description |
|---|
| Version | Yes | String | Function version name |
| Key | Yes | String | Match rule key, default 'invoke.headers.X-Tcb-Route-Key' |
| Method | Yes | String | Match method, default 'range' |
| Expression | Yes | String | Range match rule: open or closed interval (a,b) [a,b], where a, b are integers |
Only two configuration methods are supported: 1. Specify single version with traffic ratio, remaining traffic goes to $LATEST; 2. Specify two versions to allocate all traffic, as shown in examples below
3. Return Result
| Field | Type | Description |
|---|
| RequestId | String | Request ID |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { functions } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});
async function test() {
const updateFunctionAliasConfigRes1 =
await functions.updateFunctionAliasConfig({
functionName: "sum",
name: "$DEFAULT",
functionVersion: "$LATEST",
routingConfig: {
AddtionVersionMatchs: [
{
Expression: "[0,3)",
Key: "invoke.headers.X-Tcb-Route-Key",
Method: "range",
Version: "1",
},
],
},
});
console.log("updateFunctionAliasConfig1", updateFunctionAliasConfigRes1);
const updateFunctionAliasConfigRes2 =
await functions.updateFunctionAliasConfig({
functionName: "sum",
name: "$DEFAULT",
functionVersion: "$LATEST",
routingConfig: {
AddtionVersionMatchs: [
{
Expression: "[0,10)",
Key: "invoke.headers.X-Tcb-Route-Key",
Method: "range",
Version: "1",
},
{
Expression: "[10,100)",
Key: "invoke.headers.X-Tcb-Route-Key",
Method: "range",
Version: "2",
},
],
},
});
console.log("updateFunctionAliasConfigRes2", updateFunctionAliasConfigRes2);
}
test();
getFunctionAlias
1. Interface Description
Function: Query function version configuration (alias configuration)
Declaration: getFunctionAlias(options: IGetFunctionAlias): Promise<Object>
IGetFunctionAlias struct
| Field | Required | Type | Description |
|---|
| functionName | Yes | String | Function name |
| name | Yes | String | Alias name, default '$DEFAULT' |
3. Return Result
| Field | Type | Description |
|---|
| RequestId | String | Request ID |
| FunctionVersion | String | Alias main version |
| Name | String | Alias name |
| RoutingConfig | IRoutingConfig | Alias routing info |
| Description | String | Description |
| AddTime | String | Creation time |
| ModTime | String | Modification time |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { functions } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});
async function test() {
const getVersionConfigRes = await functions.getFunctionAlias({
name: "$DEFAULT",
functionName: "sum",
});
console.log("getVersionConfigRes", JSON.stringify(getVersionConfigRes));
}
test();