SCF
getFunctionList
1. API Description
API feature: obtain SCF list
API declaration: getFunctionList(limit, offset): Promise<Object>
This API has been supported since version 3.7.0.
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| limit | No | Number | range |
| offset | No | Number | offset |
3. Return Results
| Field | Required | Type | Description |
|---|---|---|---|
| RequestID | Required | String | Unique identifier of the request |
| TotalCount | Required | Number | Total count |
| Functions | Required | Array | Function list |
| Functions[].FunctionId | Required | String | Function ID |
| Functions[].FunctionName | Required | String | Function name |
| Functions[].Namespace | Required | String | Namespace |
| Functions[].Runtime | Required | String | Runtime |
| Functions[].AddTime | Required | String | Creation time |
| Functions[].ModTime | Required | String | Modification time |
| Functions[].Status | Required | String | Function status |
| Functions[].StatusDesc | Required | String | Status description |
| Functions[].Description | Required | 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' // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
})
async function test() {
let res = await functions.getFunctionList(20, 0)
const { Functions } = res
for(let function in Functions) {
console.log(function)
}
}
test()
createFunction
1. API Description
API feature: Creating a function
API declaration: createFunction(funcParam: ICreateFunctionParam): Promise<Object>
⚠️ Starting from version 2.0.0, the request parameters for this API have been changed from (func: ICloudFunction, functionRootPath: string, force: boolean, base64Code: string) to (funcParam: ICreateFunctionParam), which is an incompatible change.
2. Input Parameters
ICreateFunctionParam
| Field | Required | Type | Description |
|---|---|---|---|
| func | Required | ICloudFunction | Function configuration |
| functionRootPath | No | String | User's local function file directory |
| force | No | Boolean | whether to overwrite functions with the same name, 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 | Code deployment method: cos or zip, default cos (zip file size limit: 1.5MB) |
💡 Upload method description: By default,
cosis used;zipcan be specified (with a 1.5MB limit).
Note: If you only need to update the function code, use the updateFunctionCode API.
Note: If an SCF with the same name exists and the force option is set to true, the SDK will automatically update the function code, update the function configuration, and create triggers.
Note: createFunction supports multiple methods for creating functions:
- The user directly specifies the path to the function folder.
- The user specifies the local root directory
functionRootPathcontaining the function folder, and determines the function file path based onfunctionRootPath + name. - The user compresses the function code package into a zip file, performs base64 encoding, and provides the
base64Codeparameter.
Note: ICloudFunctionConfig is the old parameter structure.
ICloudFunctionConfig
| Field | Required | Type | Description |
|---|---|---|---|
| timeout | No | Number | Function timeout period in seconds, default is 10 seconds |
| envVariables | No | Record<string, string | number | boolean> | An object containing key-value pairs of environment variables |
| vpc | No | IFunctionVPC | VPC configuration |
| runtime | No | String | Runtime environment configuration. Valid values: Nodejs20.19, Nodejs18.15, Nodejs16.13, Nodejs14.18, Nodejs12.16, Nodejs10.15, Php8.0, Php7.4, Php7.2, Python3.10, Python3.9, Python3.7, Python3.6, Python2.7, Golang1, Java8, Java11 |
| installDependency | No | Boolean | whether to install dependencies, only valid for Node.js |
| memorySize | No | Number | Memory size during function runtime in MB, default is 256 |
| l5 | No | Boolean | whether to enable L5 access |
| role | No | String | Function bound to a role |
ICloudFunction
| Field | Required | Type | Description |
|---|---|---|---|
| name | Required | String | Function name |
| description | No | String | Function description |
| type | No | String | Function type. Valid values: Event (default) or HTTP |
| timeout | No | Number | Function timeout period in seconds, default is 10 seconds |
| envVariables | No | Record<string, string | number | boolean> | An object containing key-value pairs of environment variables |
| vpc | No | IFunctionVPC | VPC configuration |
| runtime | No | String | Runtime environment configuration. Valid values: Nodejs20.19, Nodejs18.15, Nodejs16.13, Nodejs14.18, Nodejs12.16, Nodejs10.15, Php8.0, Php7.4, Php7.2, Python3.10, Python3.9, Python3.7, Python3.6, Python2.7, Golang1, Java8, Java11 |
| installDependency | No | Boolean | whether to install dependencies, only valid for Node.js |
| memorySize | No | Number | Memory size during function runtime in MB, default is 256 |
| l5 | No | Boolean | whether to enable L5 access |
| role | No | String | Role bound to the function |
| triggers | No | Array of ICloudFunctionTrigger | List of trigger configurations |
| handler | No | String | Function entry |
| ignore | No | String or Array<String> | Files to ignore when uploading function code, matched using Glob patterns |
| isWaitInstall | No | Boolean | whether to wait for dependency installation to complete |
| codeSecret | No | String | Code protection key |
| layers | No | Array<ILayerItem> | List of Layer versions to be associated with the function. Layers are overridden in the order they appear in the list. |
ILayerItem
| Field | Required | Type | Description |
|---|---|---|---|
| name | Required | String | layer name |
| version | Required | Number | Version number |
Note: handler is the function entry point. The default value for Node.js projects is index.main. The entry file must be in the root directory. For example, in Node.js projects, index.main refers to the main method in the index.js file.
Note: If using online dependency installation, the Node.js runtime must be set to a supported version such as Nodejs18.15, and a package.json file must be placed in the same directory as the entry file. Online dependency installation is currently not supported for other runtimes.
If not using online dependency installation, the Node.js runtime does not require filling in runtime (default Nodejs18.15), but when using Php and Java, runtime must be filled in.
ICloudFunctionTrigger
| Field | Required | Type | Description |
|---|---|---|---|
| name | Required | String | Trigger name |
| type | Required | String | Trigger type. Valid values: timer |
| config | Required | String | Trigger configuration. For timer triggers, config should be in cron expression format |
IFunctionVPC
| Field | Required | Type | Description |
|---|---|---|---|
| vpcId | Required | String | VPC Id |
| subnetId | Required | String | VPC subnet Id |
⚠️ When testing, please confirm in the TCB console that the function was created and deployed successfully. It is possible that creation succeeds and
createFunctionreturns successfully, but deployment fails. Deployment failures are usually caused by a mismatch between thehandlerparameter and the source code package.
3. Return Results
| Field | Required | Type | Description |
|---|---|---|---|
| RequestId | Required | 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", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
async function test() {
await functions.createFunction({
func: {
// The name of the function folder under the functions folder, which is the function name
name: "app",
// Timeout
timeout: 5,
// Environment variables
envVariables: {
key: "value",
akey: "c",
},
runtime: "Nodejs18.15",
// Function trigger. For details, see the documentation: https://cloud.tencent.com/document/product/876/32314
triggers: [
{
// name: The name of the trigger
name: "myTrigger",
// type: Trigger type. Currently only supports timer (i.e., a scheduled trigger)
type: "timer",
// config: Trigger configuration. Under timer triggers, config should be in cron expression format
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. API Description
API feature: updates SCF code
API declaration: updateFunctionCode(funcParam: IUpdateFunctionCodeParam): Promise<Object>
⚠️ Starting from version 2.0.0, the request parameters for this API have been changed from (func: ICloudFunction, functionRootPath: string, base64Code: string) to (funcParam: IUpdateFunctionCodeParam), which is an incompatible change.
2. Input Parameters
IUpdateFunctionCodeParam
| Field | Required | Type | Description |
|---|---|---|---|
| func | Required | ICloudFunction | Function configuration |
| functionPath | No | String | Function folder path |
| functionRootPath | No | String | User's local function file directory |
| base64Code | No | String | base64-encoded function file |
| codeSecret | No | String | Code protection key |
| deployMode | No | String | Code deployment method: cos or zip, default cos (zip file size limit: 1.5MB) |
💡 Upload method description: By default,
cosis used;zipcan be specified (with a 1.5MB limit).
3. Return Results
| Field | Required | Type | Description |
|---|---|---|---|
| RequestId | Required | 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", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
async function test() {
let res = await functions.updateFunctionCode({
func: {
// The name of the function folder under the functions folder, which is the function name
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. API Description
API feature: updates SCF configuration
API declaration: updateFunctionConfig(funcParam: ICloudFunction): Promise<Object>
⚠️ Starting from version 2.0.0, the request parameters for this API have been changed from (name: string, config: ICloudFunctionConfig) to (funcParam: ICloudFunction), which is an incompatible change.
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| funcParam | Required | ICloudFunction | Function configuration |
3. Return Results
| Field | Required | Type | Description |
|---|---|---|---|
| RequestId | Required | 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", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
async function test() {
let res = await functions.updateFunctionConfig({
name: "app",
timeout: 6,
});
console.log(res);
}
test();
deleteFunction
1. API Description
API feature: Delete SCF
API declaration: deleteFunction(name: string): Promise<Object>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| name | Required | String | function name |
| qualifier | No | String | Version number to be deleted. If left blank, all versions under the function will be deleted by default |
3. Return Results
| Field | Required | Type | Description |
|---|---|---|---|
| RequestId | Required | 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", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
async function test() {
await functions.deleteFunction("functionName", "1");
}
test();
getFunctionDetail
1. API Description
API feature: obtain SCF details
API declaration: getFunctionDetail(name: string, codeSecret?: string): Promise<Object>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| name | Required | String | Function name |
| codeSecret | No | String | Code protection key |
3. Return Results
| Field | Required | Type | Description |
|---|---|---|---|
| RequestId | Required | String | Unique identifier of the request |
| FunctionName | Required | String | Function name |
| FunctionId | Required | String | Function ID |
| Namespace | Required | String | Namespace |
| Runtime | Required | String | Runtime |
| Handler | Required | String | Function entry |
| Description | Required | String | Function description |
| CodeSize | Required | Number | Code size |
| AddTime | Required | String | Function creation time |
| ModTime | Required | String | Function modification time |
| Environment | Required | Object | Environment variables of the function |
| Environment.Variables | Required | Array | Environment variables array |
| Environment.Variables[].Key | Required | String | Variable's Key |
| Environment.Variables[].Value | Required | String | Variable's Value |
| MemorySize | Required | Number | Maximum memory for the function |
| Timeout | Required | Number | Function timeout period |
| CodeInfo | Required | String | Function code |
| Status | Required | String | Function status |
| StatusDesc | Required | String | Status description |
| Triggers | Required | Array<ITrigger> | Function trigger list |
| Layers | No | Array<ILayerVersionInfo> | List of layers associated with the function |
| VpcConfig | No | Object | VPC configuration |
| VpcConfig.VpcId | No | String | VPC ID |
| VpcConfig.SubnetId | No | String | Subnet ID |
| Role | No | String | Role bound to the function |
| InstallDependency | Required | String | Whether to install dependencies (TRUE/FALSE) |
| FunctionVersion | Required | String | Function version |
| Type | Required | String | Function type |
ITrigger
| Field | Required | Type | Description |
|---|---|---|---|
| Name | Required | String | Trigger name |
| Type | Required | String | Trigger type |
| TriggerName | Required | String | Trigger name |
| TriggerDesc | Required | String | Trigger detailed configuration |
| Config | Required | String | Trigger configuration |
| ModTime | Required | Timestamp | Trigger last modification time |
| AddTime | Required | Timestamp | Trigger creation time |
| AvailableStatus | Required | String | Trigger status |
| Enable | Required | Number | Enable switch |
| CustomArgument | No | String | Custom arguments |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { functions } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
async function test() {
let res = await functions.getFunctionDetail("functionName");
console.log(res); // Outputs SCF details
}
test();
invokeFunction
1. API Description
API feature: Invoke SCF
API declaration: invokeFunction(name: string, params: object): Promise<Object>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| functionName | Required | String | Function name |
| params | Optional | Object | Optional parameters for function invocation input |
3. Return Results
| Field | Required | Type | Description |
|---|---|---|---|
| RequestId | Required | String | Unique identifier of the request |
| FunctionRequestId | Required | String | ID of the function execution |
| Duration | Required | Number | Indicates the execution duration of the function in milliseconds. Returns empty for asynchronous invocations. |
| BillDuration | Required | Number | Indicates the billing duration of the function in milliseconds. Returns empty for asynchronous invocations. |
| MemUsage | Required | Number | Memory size during function execution in Bytes. Returns empty for asynchronous invocations. |
| InvokeResult | Required | Number | 0 indicates success. Returns empty for asynchronous invocations. |
| RetMsg | Required | String | Indicates the return of the function execution. Returns empty for asynchronous invocations. |
| ErrMsg | Required | String | Indicates the error return message of the function execution. Returns empty for asynchronous invocations. |
| Log | Required | String | Indicates the log output during the execution process. Returns empty for asynchronous invocations. |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { functions } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
async function test() {
const res = await functions.invokeFunction("app", {
a: 1,
});
console.log(res.RetMsg);
}
test();
getFunctionLogsV2
This API does not return specific log details. Please use the RequestId from individual logs in the LogList array returned by this API to call the getFunctionLogDetail function to query log details.
1. API Description
API feature: obtain SCF invocation log list
API declaration: getFunctionLogsV2(options: IFunctionLogOptionsV2): Promise<Object>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| options | Required | IFunctionLogOptions | Log query options |
IFunctionLogOptionsV2
| Field | Required | Type | Description |
|---|---|---|---|
| name | Required | String | Function name |
| offset | No | Number | The offset of data. Offset+Limit cannot exceed 10000. |
| limit | No | Number | The length of returned data. Offset+Limit cannot exceed 10000. |
| startTime | No | String | The specific date for the query, e.g., 2017-05-16 20:00:00, must be within one day of EndTime |
| endTime | No | String | The specific date for the query, e.g., 2017-05-16 20:59:59, must be within one day of StartTime |
| requestId | No | String | The requestId corresponding to the execution of this function |
| qualifier | No | String | Function version, default is $LATEST |
3. Return Results
| Field | Required | Type | Description |
|---|---|---|---|
| RequestId | Required | String | Unique identifier of the request |
| LogList[] | Required | Array | Return of function execution |
| Data[].RequestId | Yes | String | Function log request ID |
| Data[].RetryNum | Yes | String | Function log retry ID |
| Data[].RetCode | Yes | Number | Function execution status code, 200/500 |
| Data[].StartTime | Required | 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", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
const { functions } = manager;
async function test() {
const logs = await functions.getFunctionLogsV2({
name: "app",
startTime: "2025-07-19 09:00:00",
endTime: "2025-07-19 19:00:00",
});
const { LogList } = logs;
for (let item of LogList) {
// console.log(item.RequestId);
const logId = item.RequestId;
// Query cls logs based on 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. API Description
API feature: Query log details based on the requestId of the log returned by getFunctionLogsV2
API declaration: getFunctionLogDetail(options: IFunctionLogDetailOptions): Promise<Object>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| options | Required | IFunctionLogDetailOptions | Log details query options |
IFunctionLogDetailOptions
| Field | Required | Type | Description |
|---|---|---|---|
| startTime | No | String | The specific date for the query, e.g., 2017-05-16 20:00:00, must be within one day of EndTime |
| endTime | No | String | The specific date for the query, e.g., 2017-05-16 20:59:59, must be within one day of StartTime |
| logRequestId | Required | String | The requestId corresponding to the execution of this function |
3. Return Results
| Field | Required | Type | Description |
|---|---|---|---|
| RequestId | No | String | Request ID |
| StartTime | No | String | Invocation time |
| Duration | No | Number | Invocation duration (ms) |
| MemUsage | No | Number | Memory usage |
| LogJson | No | String | Log Content |
| RetMsg | No | String | SCF return result |
| 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", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
const { functions } = manager;
async function test() {
const logs = await functions.getFunctionLogsV2({
name: "app",
startTime: "2025-07-19 09:00:00",
endTime: "2025-07-19 19:00:00",
});
const { LogList } = logs;
for (let item of LogList) {
// console.log(item.RequestId);
const logId = item.RequestId;
// Query cls logs based on 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. API Description
API feature: copy SCF
API declaration: copyFunction(name, newFunctionName, targetEnvId, force): Promise<Object>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| name | Required | String | Original function name |
| newFunctionName | Required | String | New function name |
| targetEnvId | Required | String | New environment ID (fill in when copying functions across environments) |
| force | No | Boolean | whether to overwrite functions with the same name |
3. Return Results
| Field | Required | Type | Description |
|---|---|---|---|
| RequestId | Required | 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", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
async function test() {
await functions.copyFunction();
}
test();
createFunctionTriggers
1. API Description
API feature: Creates SCF triggers
API declaration: createFunctionTriggers(name: string, triggers: ICloudFunctionTrigger[]): Promise<Object>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| name | Required | String | Function name |
| triggers | Required | ICloudFunctionTrigger | Trigger configuration array |
3. Return Results
| Field | Required | Type | Description |
|---|---|---|---|
| RequestId | Required | 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", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
async function test() {
await functions.createFunctionTriggers("app", [
{
// name: The name of the trigger
name: "newTrigger",
// type: Trigger type. Currently only supports timer (i.e., a scheduled trigger)
type: "timer",
// config: Trigger configuration. Under timer triggers, config should be in cron expression format
config: "0 0 2 1 * * *",
},
]);
}
test();
deleteFunctionTrigger
1. API Description
API feature: Delete SCF trigger
API declaration: deleteFunctionTrigger(name: string, triggerName: string): Promise<Object>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| name | Required | String | Function name |
| triggerName | Required | String | Trigger name |
3. Return Results
| Field | Required | Type | Description |
|---|---|---|---|
| RequestId | Required | 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", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
async function test() {
await functions.deleteFunctionTrigger("app", "newTrigger");
}
test();
getFunctionDownloadUrl
1. API Description
API feature: obtain SCF code download link
API declaration: getFunctionDownloadUrl(functionName:string, codeSecret?: string): Promise<Object>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| functionName | Required | String | Function name |
| codeSecret | No | String | Code protection key |
3. Return Results
| Field | Required | Type | Description |
|---|---|---|---|
| RequestID | Required | String | Unique identifier of the request |
| Url | Required | String | Function code download link |
| CodeSha256 | Required | String | SHA256 hash of the function |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { functions } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
async function test() {
const res = await functions.getFunctionDownloadUrl("sum");
const { Url } = res;
console.log(Url);
}
test();
updateFunctionIncrementalCode
1. API Description
API feature: Incremental upload of SCF code
API declaration: updateFunctionIncrementalCode(funcParam: IUpdateFunctionIncrementalCodeParam): Promise<Object>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| funcParam | Required | IUpdateFunctionIncrementalCodeParam structure | Incremental update function configuration items |
IUpdateFunctionIncrementalCodeParam Structure
| Field | Required | Type | Description |
|---|---|---|---|
| func | Required | ICloudFunction | Function configuration item. For incremental updates, only the name and runTime fields are currently supported for configuration. |
| functionRootPath | Required | String | User's local function file directory |
| deleteFiles | No | Array<String> | List of files and directories to be deleted, using relative paths. When deleting a directory, the path must end with '/'. |
| addFiles | No | String | glob patterns for files/directories that are added or modified. Currently, only a single file or a single directory is supported. |
⚠️ When specifying paths, please note the differences between Linux and Windows ('/' vs '\') ⚠️ Incremental updates to package.json do not trigger dependency installation
3. Return Results
| Field | Required | Type | Description |
|---|---|---|---|
| RequestId | Required | 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", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
async function test() {
// There is a local sum function folder, and a new test/index.js file is added (the relative path of index.js is sum/test/index.js).
await functions.updateFunctionIncrementalCode({
func: {
name: "sum",
runTime: "Nodejs18.15",
},
addFiles: "test/index.js",
});
// There is a local sum function folder, and a new test/ directory is added (the relative path of test is sum/test/).
await functions.updateFunctionIncrementalCode({
func: {
name: "sum",
runTime: "Nodejs18.15",
},
addFiles: "test/*", // Matches all files in the test directory. glob patterns are used here instead of relative paths.
});
// There is a local sum function folder, delete test/index.js (the relative path of index.js is sum/test/index.js).
await functions.updateFunctionIncrementalCode({
func: {
name: "sum",
runTime: "Nodejs18.15",
},
deleteFiles: ["test/index.js"],
});
// There is a local sum function folder, delete the test/ directory (the relative path of test is sum/test/).
await functions.updateFunctionIncrementalCode({
func: {
name: "sum",
runTime: "Nodejs18.15",
},
deleteFiles: ["test/"], // When deleting a directory, the path must end with '/'
});
}
test();
createLayer
1. API Description
API feature: Publish layer version
API declaration: createLayer(options: IFunctionLayerOptions): Promise<Object>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| options | Required | IFunctionLayerOptions structure | Request parameter |
IFunctionLayerOptions Structure
| Field | Required | Type | Description |
|---|---|---|---|
| contentPath | No | String | You can specify contentPath as a folder path or a ZIP file path. |
| base64Content | No | String | base64 encoding of the file |
| name | Required | String | Layer name, supports uppercase and lowercase letters, digits, hyphens, and underscores; must start with a letter; cannot end with a hyphen or underscore; length 1-64 characters |
| runtimes | Required | Array<String> | Applicable runtimes for the layer (multiple selections allowed). The available options correspond to the function's Runtime options. |
| description | No | String | Layer version description |
| licenseInfo | No | String | Layer software license |
3. Return Results
| Field | Required | Type | Description |
|---|---|---|---|
| RequestId | Required | String | Request ID |
| LayerVersion | Required | Number | Layer version number |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { functions } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
async function test() {
const res = await functions.createLayer({
name: layerName,
contentPath: "./test/functions/luke/",
runtimes: ["Nodejs18.15"],
});
console.log(res.LayerVersion);
}
test();
deleteLayerVersion
1. API Description
API feature: Delete layer version
API declaration: deleteLayerVersion(options: ILayerOptions): Promise<Object>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| options | Required | ILayerOptions structure | Request parameter |
ILayerOptions Structure
| Field | Required | Type | Description |
|---|---|---|---|
| name | Required | String | layer name |
| version | Required | Number | Version number |
3. Return Results
| Field | Required | Type | Description |
|---|---|---|---|
| RequestId | Required | 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", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
async function test() {
const res = await functions.deleteLayerVersion({
name: layerName,
version: 1,
});
console.log(res.RequestId);
}
test();
listLayerVersions
1. API Description
API feature: Obtain layer version list
API declaration: listLayerVersions(options: IVersionListOptions): Promise<Object>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| options | Required | IVersionListOptions structure | Request parameter |
IVersionListOptions Structure
| Field | Required | Type | Description |
|---|---|---|---|
| name | Required | String | layer name |
| runtimes | No | Array<String> | Version number |
3. Return Results
| Field | Required | Type | Description |
|---|---|---|---|
| RequestId | Required | String | Request ID |
| LayerVersions | Required | Array<ILayerVersionInfo> | File layer details |
ILayerVersionInfo Structure
| Field | Required | Type | Description |
|---|---|---|---|
| CompatibleRuntimes | No | Array<String> | Runtime environments applicable to the version |
| AddTime | No | String | Creation time |
| Description | No | String | Version description |
| LicenseInfo | No | String | License information |
| LayerVersion | No | Number | Version number |
| LayerName | No | String | Layer name |
| Status | No | String | Current status of the specific layer version: Active (Normal), Publishing (In progress), PublishFailed (Failed), Deleted (Deleted) |
| Stamp | No | String | Stamp mark |
| Tags | No | Array<Object> | Tag information |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { functions } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
async function test() {
const res = await functions.listLayerVersions({
name: layerName,
});
console.log(res.LayerVersions);
}
test();
listLayers
1. API Description
API feature: Obtain layer list
API declaration: listLayers(options: ILayerListOptions): Promise<Object>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| options | Required | ILayerListOptions structure | Request parameter |
ILayerListOptions Structure
| Field | Required | Type | Description |
|---|---|---|---|
| offset | No | Number | offset |
| limit | No | Number | limit |
| runtime | No | String | Compatible runtime |
| searchKey | No | String | Query key for fuzzy matching by name |
3. Return Results
| Field | Required | Type | Description |
|---|---|---|---|
| RequestId | Required | String | Request ID |
| TotalCount | Required | Number | Total layer count |
| Layers | Required | Array<ILayerVersionInfo> | File layer details |
ILayerVersionInfo Structure
| Field | Required | Type | Description |
|---|---|---|---|
| CompatibleRuntimes | No | Array<String> | Runtime environments applicable to the version |
| AddTime | No | String | Creation time |
| Description | No | String | Version description |
| LicenseInfo | No | String | License information |
| LayerVersion | No | Number | Version number |
| LayerName | No | String | Layer name |
| Status | No | String | Current status of the specific layer version: Active (Normal), Publishing (In progress), PublishFailed (Failed), Deleted (Deleted) |
| Stamp | No | String | Stamp mark |
| Tags | No | Array<Object> | Tag information |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { functions } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
async function test() {
const res = await functions.listLayers({});
console.log(res.Layers);
}
test();
getLayerVersion
1. API Description
API feature: Obtain layer version details
API declaration: getLayerVersion(options: ILayerOptions): Promise<Object>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| options | Required | ILayerOptions structure | Request parameter |
ILayerOptions Structure
| Field | Required | Type | Description |
|---|---|---|---|
| name | Required | String | layer name |
| version | Required | Number | Version number |
3. Return Results
| Field | Required | Type | Description |
|---|---|---|---|
| RequestId | Required | String | Request ID |
| CompatibleRuntimes | Required | Array<String> | Compatible runtime |
| CodeSha256 | Required | String | SHA256 hash of the version file in the layer |
| Location | Required | String | Download URL of the version file in the layer |
| AddTime | Required | String | Creation time of the version |
| Description | Required | String | Version description |
| LicenseInfo | Required | String | License information |
| LayerVersion | Required | Number | Version number |
| LayerName | Required | String | layer name |
| Status | Yes | String | Current status of the specific layer version: Active (Normal), Publishing (In progress), PublishFailed (Failed), Deleted (Deleted) |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const { functions } = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
async function test() {
const res = await functions.getLayerVersion({ name: layerName, version: 2 });
console.log(res.LayerVersion);
}
test();
setProvisionedConcurrencyConfig
1. API Description
API feature: Setting function provisioned concurrency
API declaration: setProvisionedConcurrencyConfig(options: ISetProvisionedConcurrencyConfig): Promise<Object>
2. Input Parameters
ISetProvisionedConcurrencyConfig Struct
| Field | Required | Type | Description |
|---|---|---|---|
| functionName | Required | String | function name |
| qualifier | Yes | String | function version name |
| versionProvisionedConcurrencyNum | Required | Number | provisioned concurrency for the current version |
3. Return Results
| Field | Required | Type | Description |
|---|---|---|---|
| RequestId | Required | 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", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
async function test() {
const setProvisionedConcurrencyConfigRes =
await functions.setProvisionedConcurrencyConfig({
functionName: "sum",
qualifier: "1", // version 1
versionProvisionedConcurrencyNum: 10, // set concurrency to 10
});
console.log(setProvisionedConcurrencyConfigRes);
}
test();
getProvisionedConcurrencyConfig
1. API Description
API feature: Querying function provisioned concurrency
API declaration: getProvisionedConcurrencyConfig(options: IGetProvisionedConcurrencyConfig): Promise<Object>
2. Input Parameters
IGetProvisionedConcurrencyConfig Struct
| Field | Required | Type | Description |
|---|---|---|---|
| functionName | Required | String | Function name |
| qualifier | No | String | Function version name. If left blank, the provisioned concurrency information for all versions of the function will be queried. |
3. Return Results
| Field | Type | Description |
|---|---|---|
| RequestId | String | Request ID |
| UnallocatedConcurrencyNum | Number | Remaining configurable provisioned concurrency for the function. |
| Allocated | Array<IVersionProvisionedConcurrencyInfo> | Details of the provisioned concurrency configuration for the function. |
IVersionProvisionedConcurrencyInfo
| Field | Type | Description |
|---|---|---|
| AllocatedProvisionedConcurrencyNum | Number | Configured provisioned concurrency. |
| AvailableProvisionedConcurrencyNum | Number | Provisioned concurrency |
| Status | String | Provisioning task status. Done indicates completed, InProgress indicates in progress, Failed indicates partially or completely failed. |
| StatusReason | String | Task status reason |
| 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", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
async function test() {
const getProvisionedConcurrencyConfigRes =
await functions.getProvisionedConcurrencyConfig({
functionName: "sum",
qualifier: "1", // version 1
});
console.log(getProvisionedConcurrencyConfigRes);
}
test();
deleteProvisionedConcurrencyConfig
1. API Description
API feature: Deleting function provisioned concurrency
API declaration: deleteProvisionedConcurrencyConfig(options: IDeleteProvisionedConcurrencyConfig): Promise<Object>
2. Input Parameters
IDeleteProvisionedConcurrencyConfig Struct
| Field | Required | Type | Description |
|---|---|---|---|
| functionName | Required | String | Function name |
| qualifier | Required | String | Function version name. If left blank, the provisioned concurrency information for all versions of the function will be queried. |
3. Return Results
| 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", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
async function test() {
const deleteProvisionedConcurrencyConfigRes =
await functions.deleteProvisionedConcurrencyConfig({
functionName: "sum",
qualifier: "1", // version 1
});
console.log(deleteProvisionedConcurrencyConfigRes);
}
test();
publishVersion
1. API Description
API feature: Publish new function version
API declaration: publishVersion(options: IPublishVersionParams): Promise<Object>
2. Input Parameters
IPublishVersionParams Structure
| Field | Required | Type | Description |
|---|---|---|---|
| functionName | Required | String | Function name |
| description | No | String | Version description |
3. Return Results
| Field | Type | Description |
|---|---|---|
| RequestId | String | Request ID |
| FunctionVersion | String | Function version |
| CodeSize | Number | Code size |
| MemorySize | Number | Maximum available memory |
| Handler | String | Function entry |
| Timeout | Number | Function timeout period |
| Runtime | String | Runtime |
| 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", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
async function test() {
const createNewVersionRes = await functions.publishVersion({
functionName: "sum",
description: "test", // To create a new version for the sum function with description 'test'
});
console.log(createNewVersionRes);
}
test();
listVersionByFunction
1. API Description
API feature: Query function version list
API declaration: listVersionByFunction(options: IListFunctionVersionParams): Promise<Object>
2. Input Parameters
IListFunctionVersionParams Structure
| Field | Required | Type | Description |
|---|---|---|---|
| functionName | Required | String | Function name |
| offset | No | Number | Data offset, default value is 0 |
| limit | No | Number | Returned data length, default value is 20 |
| order | No | Number | Specifies the order of results: ASC (ascending) or DESC (descending) |
| orderBy | No | Number | Specifies the field to sort the returned results by. Supported fields: AddTime, ModTime |
3. Return Results
| Field | Type | Description |
|---|---|---|
| RequestId | String | Request ID |
| TotalCount | String | Total number of function versions |
| FunctionVersion | Array<String> | List of function version names |
| Versions | Array<IFunctionVersion> | List of function versions |
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", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
async function test() {
const functionVersions = await functions.listVersionByFunction({
functionName: "sum",
});
console.log(functionVersions);
}
test();
updateFunctionAliasConfig
1. API Description
API feature: updates function version configuration (alias configuration)
API declaration: updateFunctionAliasConfig(options: IUpdateFunctionAliasConfig): Promise<Object>
2. Input Parameters
IUpdateFunctionAliasConfig Structure
| Field | Required | Type | Description |
|---|---|---|---|
| functionName | Required | String | Function name |
| name | Required | String | Alias name, default to '$DEFAULT' |
| functionVersion | Required | String | Primary version of the alias, default to '$LATEST' |
| description | No | String | Alias description |
| routingConfig | No | IRoutingConfig | Routing configuration |
IRoutingConfig
| Field | Required | Type | Description |
|---|---|---|---|
| AdditionalVersionWeights | No | Array<IVersionWeight> | Version weight configuration (gray release) |
| AddtionVersionMatchs | No | Array<IVersionMatch> | Additional version matches for rule-based routing |
IVersionWeight
| Field | Required | Type | Description |
|---|---|---|---|
| Version | Required | String | Function version name |
| Weight | Required | Number | Traffic weight for this version (0-100) |
IVersionMatch
| Field | Required | Type | Description |
|---|---|---|---|
| Version | Required | String | Function version name |
| Key | Required | String | The key for rule matching. During invocation, pass this key to match the rule and route to the specified version. Default: 'invoke.headers.X-Tcb-Route-Key' |
| Method | Required | String | Matching method, defaults to 'range' |
| Expression | Required | String | The range matching rule requires: an open or closed interval description (a,b) or [a,b], where both a and b are integers. |
Only two configuration methods are supported: 1. Specify a single version and its corresponding traffic ratio, with the remaining traffic routed to the $LATEST version; 2. Specify two versions to allocate all traffic, as shown in the following example
3. Return Results
| 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", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
async function test() {
const updateFunctionAliasConfigRes1 =
await functions.updateFunctionAliasConfig({
functionName: "sum",
name: "$DEFAULT",
functionVersion: "$LATEST",
routingConfig: {
AddtionVersionMatchs: [
{
Expression: "[0,3)", // Set the traffic ratio of version 1 to 3%, with the remaining 97% of traffic directed to the latest version
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)", // Set the traffic ratio of version 1 to 10%
Key: "invoke.headers.X-Tcb-Route-Key",
Method: "range",
Version: "1",
},
{
Expression: "[10,100)", // Set the traffic ratio of version 2 to 90%
Key: "invoke.headers.X-Tcb-Route-Key",
Method: "range",
Version: "2",
},
],
},
});
console.log("updateFunctionAliasConfigRes2", updateFunctionAliasConfigRes2);
}
test();
getFunctionAlias
1. API Description
API feature: queries function version configuration (alias configuration)
API declaration: getFunctionAlias(options: IGetFunctionAlias): Promise<Object>
2. Input Parameters
IGetFunctionAlias Struct
| Field | Required | Type | Description |
|---|---|---|---|
| functionName | Required | String | Function name |
| name | Required | String | Alias name, default to '$DEFAULT' |
3. Return Results
| Field | Type | Description |
|---|---|---|
| RequestId | String | Request ID |
| FunctionVersion | String | Alias-targeted primary version |
| Name | String | Alias name |
| RoutingConfig | IRoutingConfig | Alias routing information |
| 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", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
async function test() {
// Query traffic configuration ratio
const getVersionConfigRes = await functions.getFunctionAlias({
name: "$DEFAULT",
functionName: "sum",
});
console.log("getVersionConfigRes", JSON.stringify(getVersionConfigRes));
}
test();
listFunctions
This API will be deprecated in the future. It is recommended to use getFunctionList()
1. API Description
API feature: obtain SCF list
API declaration: listFunctions(limit, offset): Promise<Object>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| limit | No | Number | range |
| offset | No | Number | offset |
3. Return Results
| Field | Required | Type | Description |
|---|---|---|---|
| RequestID | Required | String | Unique identifier of the request |
| TotalCount | Required | Number | Total count |
| Functions | Required | Array | Function list |
| Functions[].FunctionId | Required | String | Function ID |
| Functions[].FunctionName | Required | String | Function name |
| Functions[].Namespace | Required | String | Namespace |
| Functions[].Runtime | Required | String | Runtime |
| Functions[].AddTime | Required | String | Creation time |
| Functions[].ModTime | Required | 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' // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
})
async function test() {
let res = await functions.listFunctions(20, 0)
const { Functions } = res
for(let function in Functions) {
console.log(function)
}
}
test()
getFunctionLogs
This API is deprecated. It is recommended to use app.log.searchClsLog to query SCF logs.
1. API Description
API feature: obtain SCF invocation logs
API declaration: getFunctionLogs(options: IFunctionLogOptions): Promise<Object>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| options | Required | IFunctionLogOptions | Log query options |
IFunctionLogOptions
| Field | Required | Type | Description |
|---|---|---|---|
| name | Required | String | Function name |
| offset | No | Number | The offset of data. Offset+Limit cannot exceed 10000. |
| limit | No | Number | The length of returned data. Offset+Limit cannot exceed 10000. |
| order | No | String | Specifies the sort order for logs: 'asc' (ascending) or 'desc' (descending) |
| orderBy | No | String | Sorts logs by a specific field. Supported fields: function_name, duration, mem_usage, start_time |
| startTime | No | String | The specific date for the query, e.g., 2017-05-16 20:00:00, must be within one day of EndTime |
| endTime | No | String | The specific date for the query, e.g., 2017-05-16 20:59:59, must be within one day of StartTime |
| requestId | No | String | The requestId corresponding to the execution of this function |
3. Return Results
| Field | Required | Type | Description |
|---|---|---|---|
| RequestId | Required | String | Unique identifier of the request |
| TotalCount | Required | String | The total number of function logs |
| Data[] | Required | Array | Return of function execution |
| Data[].RequestId | Yes | String | The requestId corresponding to the execution of this function |
| Data[].FunctionName | Yes | String | Function name |
| Data[].RetCode | Yes | Number | Function execution result; 0 indicates success, any other value indicates failure |
| Data[].InvokeFinished | Yes | Number | Whether the function invocation is finished; 1 indicates finished, any other value indicates an invocation exception |
| Data[].StartTime | Required | String | Function execution start time |
| Data[].Duration | Required | Number | Indicates the execution duration of the function in milliseconds. Returns empty for asynchronous invocations. |
| Data[].BillDuration | Required | Number | Indicates the billing duration of the function in milliseconds. Returns empty for asynchronous invocations. |
| Data[].MemUsage | Required | Number | Memory usage during function execution in Bytes. Returns empty for asynchronous invocations. |
| Data[].RetMsg | Required | String | Indicates the return of the function execution. Returns empty for asynchronous invocations. |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const manager = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId", // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
});
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);
// Query cls logs based on requestId
const clsLogRes = await manager.commonService().call({
Action: "SearchClsLog",
Param: {
EnvId: cloudBaseConfig.envId,
StartTime: "2021-06-11 11:06:20", // Start time
EndTime: "2021-06-30 11:06:20", // End time
Limit: 100,
Sort: "asc",
QueryString: `requestId:${item.RequestId}`,
},
});
console.log("clsLogRes", clsLogRes);
}
}
test();
batchCreateTriggers
1. API Description
API feature: Creates triggers for multiple SCFs in batches.
API declaration: app.functions.batchCreateTriggers(options: IFunctionBatchOptions): Promise<void>
This API has been supported since v5.0.0.
2. Input Parameters
IFunctionBatchOptions
| Field | Required | Type | Description |
|---|---|---|---|
| functions | Required | ICloudFunctionV2[] | SCF configuration array, each item must contain name (function name) and triggers (trigger configuration array) |
| envId | No | String | Environment ID. If not passed, the environment from initialization will be used. |
| log | No | Boolean | whether to print success logs, default false |
3. Return Results
Promise<void> — resolves after all are successful; throws a CloudBaseError if any function trigger creation fails.
4. Sample Code
const CloudBase = require('@cloudbase/manager-node')
const app = new CloudBase({ secretId: 'Your SecretId', secretKey: 'Your SecretKey', envId: 'your-env-id' })
async function test() {
await app.functions.batchCreateTriggers({
functions: [
{ name: 'fn-a', triggers: [{ name: 'everyDay', type: 'timer', config: '0 0 2 * * * *' }] },
{ name: 'fn-b', triggers: [{ name: 'everyHour', type: 'timer', config: '0 0 */1 * * * *' }] }
]
})
console.log('Batch trigger creation successful')
}
test()
batchDeleteTriggers
1. API Description
API feature: Batch delete multiple SCF triggers
API declaration: app.functions.batchDeleteTriggers(options: IFunctionBatchOptions): Promise<void>
This API has been supported since v5.0.0.
2. Input Parameters
Similar to batchCreateTriggers, the triggers array within each item in the functions array must include the name field (trigger name).
IFunctionBatchOptions
| Field | Required | Type | Description |
|---|---|---|---|
| functions | Required | ICloudFunctionV2[] | SCF configuration array, each item contains name (function name) and triggers (trigger array with name) |
| envId | No | String | Environment ID |
3. Return Results
Promise<void> — resolves after all deletions are completed.
4. Sample Code
async function test() {
await app.functions.batchDeleteTriggers({
functions: [
{ name: 'fn-a', triggers: [{ name: 'everyDay' }] },
{ name: 'fn-b', triggers: [{ name: 'everyHour' }] }
]
})
console.log('Batch trigger deletion successful')
}
test()
attachLayer
1. API Description
API feature: Bind the specified file layer version to SCF
API declaration: app.functions.attachLayer(options: IAttachOptions): Promise<IResponseInfo>
This API has been supported since v5.0.0.
2. Input Parameters
IAttachOptions
| Field | Required | Type | Description |
|---|---|---|---|
| functionName | Required | String | SCF name |
| layerName | Required | String | file layer name |
| layerVersion | Required | Number | file layer version number |
| envId | No | String | Environment ID |
| codeSecret | No | String | Code Secret for the encryption function |
3. Return Results
| Field | Type | Description |
|---|---|---|
| RequestId | String | Unique identifier of the request |
4. Sample Code
async function test() {
const res = await app.functions.attachLayer({
functionName: 'my-func',
layerName: 'my-layer',
layerVersion: 2
})
console.log('File layer bound successfully, RequestId:', res.RequestId)
}
test()
unAttachLayer
1. API Description
API feature: Unbind the specified file layer version from SCF
API declaration: app.functions.unAttachLayer(options: IAttachOptions): Promise<IResponseInfo>
This API has been supported since v5.0.0.
If the target layer version does not exist in the function configuration, CloudBaseError('Layer does not exist') will be thrown.
2. Input Parameters
IAttachOptions (same as attachLayer)
| Field | Required | Type | Description |
|---|---|---|---|
| functionName | Required | String | SCF name |
| layerName | Required | String | file layer name |
| layerVersion | Required | Number | file layer version number |
| envId | No | String | Environment ID |
| codeSecret | No | String | Code Secret for the encryption function |
3. Return Results
| Field | Type | Description |
|---|---|---|
| RequestId | String | Unique identifier of the request |
4. Sample Code
async function test() {
const res = await app.functions.unAttachLayer({
functionName: 'my-func',
layerName: 'my-layer',
layerVersion: 2
})
console.log('File layer unbound successfully, RequestId:', res.RequestId)
}
test()
updateFunctionLayer
1. API Description
API feature: Overwrite the file layer list bound to SCF (full replacement)
API declaration: app.functions.updateFunctionLayer(options: ISortOptions): Promise<IResponseInfo>
This API has been supported since v5.0.0.
⚠️ This API performs full replacement. The function's bound file layer list will be completely overwritten by
layersafter invocation. For incremental operations, useattachLayer/unAttachLayer.
2. Input Parameters
ISortOptions
| Field | Required | Type | Description |
|---|---|---|---|
| functionName | Required | String | SCF name |
| layers | Required | ILayer[] | Target file layer list (full) |
| envId | No | String | Environment ID |
ILayer
| Field | Required | Type | Description |
|---|---|---|---|
| LayerName | Required | String | File layer name |
| LayerVersion | Required | Number | File layer version number |
3. Return Results
| Field | Type | Description |
|---|---|---|
| RequestId | String | Unique identifier of the request |
4. Sample Code
async function test() {
const res = await app.functions.updateFunctionLayer({
functionName: 'my-func',
layers: [
{ LayerName: 'layer-a', LayerVersion: 1 },
{ LayerName: 'layer-b', LayerVersion: 3 }
]
})
console.log('File layer updated successfully, RequestId:', res.RequestId)
}
test()
downloadLayer
1. API Description
API feature: Download the ZIP package of the specified file layer version locally.
API declaration: app.functions.downloadLayer(options: ILayerDownloadOptions): Promise<void>
This API has been supported since v5.0.0.
2. Input Parameters
ILayerDownloadOptions
| Field | Required | Type | Description |
|---|---|---|---|
| name | Required | String | file layer name |
| version | Required | Number | file layer version number |
| destPath | Required | String | local storage directory, ZIP file will be saved as <destPath>/<name>-<version>.zip |
| force | No | Boolean | reserved field, not enabled yet |
3. Return Results
Promise<void> — resolves after the download is complete; throws a CloudBaseError if a file with the same name already exists in the target path.
4. Sample Code
async function test() {
await app.functions.downloadLayer({
name: 'my-layer',
version: 2,
destPath: './downloads'
})
console.log('The file layer has been downloaded to ./downloads/my-layer-2.zip')
}
test()