Skip to main content

SCF

getFunctionList

1. API Description

API feature: obtain SCF list

API declaration: getFunctionList(limit, offset): Promise<Object>

tip

This API has been supported since version 3.7.0.

2. Input Parameters

FieldRequiredTypeDescription
limitNoNumberrange
offsetNoNumberoffset

3. Return Results

FieldRequiredTypeDescription
RequestIDRequiredStringUnique identifier of the request
TotalCountRequiredNumberTotal count
FunctionsRequiredArrayFunction list
Functions[].FunctionIdRequiredStringFunction ID
Functions[].FunctionNameRequiredStringFunction name
Functions[].NamespaceRequiredStringNamespace
Functions[].RuntimeRequiredStringRuntime
Functions[].AddTimeRequiredStringCreation time
Functions[].ModTimeRequiredStringModification time
Functions[].StatusRequiredStringFunction status
Functions[].StatusDescRequiredStringStatus description
Functions[].DescriptionRequiredStringFunction 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

FieldRequiredTypeDescription
funcRequiredICloudFunctionFunction configuration
functionRootPathNoStringUser's local function file directory
forceNoBooleanwhether to overwrite functions with the same name, defaults to false
base64CodeNoStringbase64-encoded function file
codeSecretNoStringCode protection key
functionPathNoStringFunction folder path
deployModeNoStringCode deployment method: cos or zip, default cos (zip file size limit: 1.5MB)

💡 Upload method description: By default, cos is used; zip can 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:

  1. The user directly specifies the path to the function folder.
  2. The user specifies the local root directory functionRootPath containing the function folder, and determines the function file path based on functionRootPath + name.
  3. The user compresses the function code package into a zip file, performs base64 encoding, and provides the base64Code parameter.

Note: ICloudFunctionConfig is the old parameter structure.

ICloudFunctionConfig

FieldRequiredTypeDescription
timeoutNoNumberFunction timeout period in seconds, default is 10 seconds
envVariablesNoRecord<string, string | number | boolean>An object containing key-value pairs of environment variables
vpcNoIFunctionVPCVPC configuration
runtimeNoStringRuntime 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
installDependencyNoBooleanwhether to install dependencies, only valid for Node.js
memorySizeNoNumberMemory size during function runtime in MB, default is 256
l5NoBooleanwhether to enable L5 access
roleNoStringFunction bound to a role

ICloudFunction

FieldRequiredTypeDescription
nameRequiredStringFunction name
descriptionNoStringFunction description
typeNoStringFunction type. Valid values: Event (default) or HTTP
timeoutNoNumberFunction timeout period in seconds, default is 10 seconds
envVariablesNoRecord<string, string | number | boolean>An object containing key-value pairs of environment variables
vpcNoIFunctionVPCVPC configuration
runtimeNoStringRuntime 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
installDependencyNoBooleanwhether to install dependencies, only valid for Node.js
memorySizeNoNumberMemory size during function runtime in MB, default is 256
l5NoBooleanwhether to enable L5 access
roleNoStringRole bound to the function
triggersNoArray of ICloudFunctionTriggerList of trigger configurations
handlerNoStringFunction entry
ignoreNoString or Array<String>Files to ignore when uploading function code, matched using Glob patterns
isWaitInstallNoBooleanwhether to wait for dependency installation to complete
codeSecretNoStringCode protection key
layersNoArray<ILayerItem>List of Layer versions to be associated with the function. Layers are overridden in the order they appear in the list.

ILayerItem

FieldRequiredTypeDescription
nameRequiredStringlayer name
versionRequiredNumberVersion 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

FieldRequiredTypeDescription
nameRequiredStringTrigger name
typeRequiredStringTrigger type. Valid values: timer
configRequiredStringTrigger configuration. For timer triggers, config should be in cron expression format

IFunctionVPC

FieldRequiredTypeDescription
vpcIdRequiredStringVPC Id
subnetIdRequiredStringVPC 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 createFunction returns successfully, but deployment fails. Deployment failures are usually caused by a mismatch between the handler parameter and the source code package.

3. Return Results

FieldRequiredTypeDescription
RequestIdRequiredStringRequest 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

FieldRequiredTypeDescription
funcRequiredICloudFunctionFunction configuration
functionPathNoStringFunction folder path
functionRootPathNoStringUser's local function file directory
base64CodeNoStringbase64-encoded function file
codeSecretNoStringCode protection key
deployModeNoStringCode deployment method: cos or zip, default cos (zip file size limit: 1.5MB)

💡 Upload method description: By default, cos is used; zip can be specified (with a 1.5MB limit).

ICloudFunction structure

3. Return Results

FieldRequiredTypeDescription
RequestIdRequiredStringRequest 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

FieldRequiredTypeDescription
funcParamRequiredICloudFunctionFunction configuration

ICloudFunction structure

3. Return Results

FieldRequiredTypeDescription
RequestIdRequiredStringRequest 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

FieldRequiredTypeDescription
nameRequiredStringfunction name
qualifierNoStringVersion number to be deleted. If left blank, all versions under the function will be deleted by default

3. Return Results

FieldRequiredTypeDescription
RequestIdRequiredStringRequest 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

FieldRequiredTypeDescription
nameRequiredStringFunction name
codeSecretNoStringCode protection key

3. Return Results

FieldRequiredTypeDescription
RequestIdRequiredStringUnique identifier of the request
FunctionNameRequiredStringFunction name
FunctionIdRequiredStringFunction ID
NamespaceRequiredStringNamespace
RuntimeRequiredStringRuntime
HandlerRequiredStringFunction entry
DescriptionRequiredStringFunction description
CodeSizeRequiredNumberCode size
AddTimeRequiredStringFunction creation time
ModTimeRequiredStringFunction modification time
EnvironmentRequiredObjectEnvironment variables of the function
Environment.VariablesRequiredArrayEnvironment variables array
Environment.Variables[].KeyRequiredStringVariable's Key
Environment.Variables[].ValueRequiredStringVariable's Value
MemorySizeRequiredNumberMaximum memory for the function
TimeoutRequiredNumberFunction timeout period
CodeInfoRequiredStringFunction code
StatusRequiredStringFunction status
StatusDescRequiredStringStatus description
TriggersRequiredArray<ITrigger>Function trigger list
LayersNoArray<ILayerVersionInfo>List of layers associated with the function
VpcConfigNoObjectVPC configuration
VpcConfig.VpcIdNoStringVPC ID
VpcConfig.SubnetIdNoStringSubnet ID
RoleNoStringRole bound to the function
InstallDependencyRequiredStringWhether to install dependencies (TRUE/FALSE)
FunctionVersionRequiredStringFunction version
TypeRequiredStringFunction type

ITrigger

FieldRequiredTypeDescription
NameRequiredStringTrigger name
TypeRequiredStringTrigger type
TriggerNameRequiredStringTrigger name
TriggerDescRequiredStringTrigger detailed configuration
ConfigRequiredStringTrigger configuration
ModTimeRequiredTimestampTrigger last modification time
AddTimeRequiredTimestampTrigger creation time
AvailableStatusRequiredStringTrigger status
EnableRequiredNumberEnable switch
CustomArgumentNoStringCustom 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

FieldRequiredTypeDescription
functionNameRequiredStringFunction name
paramsOptionalObjectOptional parameters for function invocation input

3. Return Results

FieldRequiredTypeDescription
RequestIdRequiredStringUnique identifier of the request
FunctionRequestIdRequiredStringID of the function execution
DurationRequiredNumberIndicates the execution duration of the function in milliseconds. Returns empty for asynchronous invocations.
BillDurationRequiredNumberIndicates the billing duration of the function in milliseconds. Returns empty for asynchronous invocations.
MemUsageRequiredNumberMemory size during function execution in Bytes. Returns empty for asynchronous invocations.
InvokeResultRequiredNumber0 indicates success. Returns empty for asynchronous invocations.
RetMsgRequiredStringIndicates the return of the function execution. Returns empty for asynchronous invocations.
ErrMsgRequiredStringIndicates the error return message of the function execution. Returns empty for asynchronous invocations.
LogRequiredStringIndicates 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

Note

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

FieldRequiredTypeDescription
optionsRequiredIFunctionLogOptionsLog query options

IFunctionLogOptionsV2

FieldRequiredTypeDescription
nameRequiredStringFunction name
offsetNoNumberThe offset of data. Offset+Limit cannot exceed 10000.
limitNoNumberThe length of returned data. Offset+Limit cannot exceed 10000.
startTimeNoStringThe specific date for the query, e.g., 2017-05-16 20:00:00, must be within one day of EndTime
endTimeNoStringThe specific date for the query, e.g., 2017-05-16 20:59:59, must be within one day of StartTime
requestIdNoStringThe requestId corresponding to the execution of this function
qualifierNoStringFunction version, default is $LATEST

3. Return Results

FieldRequiredTypeDescription
RequestIdRequiredStringUnique identifier of the request
LogList[]RequiredArrayReturn of function execution
Data[].RequestIdYesStringFunction log request ID
Data[].RetryNumYesStringFunction log retry ID
Data[].RetCodeYesNumberFunction execution status code, 200/500
Data[].StartTimeRequiredStringFunction 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

FieldRequiredTypeDescription
optionsRequiredIFunctionLogDetailOptionsLog details query options

IFunctionLogDetailOptions

FieldRequiredTypeDescription
startTimeNoStringThe specific date for the query, e.g., 2017-05-16 20:00:00, must be within one day of EndTime
endTimeNoStringThe specific date for the query, e.g., 2017-05-16 20:59:59, must be within one day of StartTime
logRequestIdRequiredStringThe requestId corresponding to the execution of this function

3. Return Results

FieldRequiredTypeDescription
RequestIdNoStringRequest ID
StartTimeNoStringInvocation time
DurationNoNumberInvocation duration (ms)
MemUsageNoNumberMemory usage
LogJsonNoStringLog Content
RetMsgNoStringSCF return result
ListOverNoBooleanPagination flag
ContextNoStringPagination 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

FieldRequiredTypeDescription
nameRequiredStringOriginal function name
newFunctionNameRequiredStringNew function name
targetEnvIdRequiredStringNew environment ID (fill in when copying functions across environments)
forceNoBooleanwhether to overwrite functions with the same name

3. Return Results

FieldRequiredTypeDescription
RequestIdRequiredStringRequest 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

FieldRequiredTypeDescription
nameRequiredStringFunction name
triggersRequiredICloudFunctionTriggerTrigger configuration array

3. Return Results

FieldRequiredTypeDescription
RequestIdRequiredStringRequest 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

FieldRequiredTypeDescription
nameRequiredStringFunction name
triggerNameRequiredStringTrigger name

3. Return Results

FieldRequiredTypeDescription
RequestIdRequiredStringRequest 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

FieldRequiredTypeDescription
functionNameRequiredStringFunction name
codeSecretNoStringCode protection key

3. Return Results

FieldRequiredTypeDescription
RequestIDRequiredStringUnique identifier of the request
UrlRequiredStringFunction code download link
CodeSha256RequiredStringSHA256 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

FieldRequiredTypeDescription
funcParamRequiredIUpdateFunctionIncrementalCodeParam structureIncremental update function configuration items

IUpdateFunctionIncrementalCodeParam Structure

FieldRequiredTypeDescription
funcRequiredICloudFunctionFunction configuration item. For incremental updates, only the name and runTime fields are currently supported for configuration.
functionRootPathRequiredStringUser's local function file directory
deleteFilesNoArray<String>List of files and directories to be deleted, using relative paths. When deleting a directory, the path must end with '/'.
addFilesNoStringglob 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

FieldRequiredTypeDescription
RequestIdRequiredStringRequest 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

FieldRequiredTypeDescription
optionsRequiredIFunctionLayerOptions structureRequest parameter

IFunctionLayerOptions Structure

FieldRequiredTypeDescription
contentPathNoStringYou can specify contentPath as a folder path or a ZIP file path.
base64ContentNoStringbase64 encoding of the file
nameRequiredStringLayer 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
runtimesRequiredArray<String>Applicable runtimes for the layer (multiple selections allowed). The available options correspond to the function's Runtime options.
descriptionNoStringLayer version description
licenseInfoNoStringLayer software license

3. Return Results

FieldRequiredTypeDescription
RequestIdRequiredStringRequest ID
LayerVersionRequiredNumberLayer 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

FieldRequiredTypeDescription
optionsRequiredILayerOptions structureRequest parameter

ILayerOptions Structure

FieldRequiredTypeDescription
nameRequiredStringlayer name
versionRequiredNumberVersion number

3. Return Results

FieldRequiredTypeDescription
RequestIdRequiredStringRequest 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

FieldRequiredTypeDescription
optionsRequiredIVersionListOptions structureRequest parameter

IVersionListOptions Structure

FieldRequiredTypeDescription
nameRequiredStringlayer name
runtimesNoArray<String>Version number

3. Return Results

FieldRequiredTypeDescription
RequestIdRequiredStringRequest ID
LayerVersionsRequiredArray<ILayerVersionInfo>File layer details

ILayerVersionInfo Structure

FieldRequiredTypeDescription
CompatibleRuntimesNoArray<String>Runtime environments applicable to the version
AddTimeNoStringCreation time
DescriptionNoStringVersion description
LicenseInfoNoStringLicense information
LayerVersionNoNumberVersion number
LayerNameNoStringLayer name
StatusNoStringCurrent status of the specific layer version: Active (Normal), Publishing (In progress), PublishFailed (Failed), Deleted (Deleted)
StampNoStringStamp mark
TagsNoArray<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

FieldRequiredTypeDescription
optionsRequiredILayerListOptions structureRequest parameter

ILayerListOptions Structure

FieldRequiredTypeDescription
offsetNoNumberoffset
limitNoNumberlimit
runtimeNoStringCompatible runtime
searchKeyNoStringQuery key for fuzzy matching by name

3. Return Results

FieldRequiredTypeDescription
RequestIdRequiredStringRequest ID
TotalCountRequiredNumberTotal layer count
LayersRequiredArray<ILayerVersionInfo>File layer details

ILayerVersionInfo Structure

FieldRequiredTypeDescription
CompatibleRuntimesNoArray<String>Runtime environments applicable to the version
AddTimeNoStringCreation time
DescriptionNoStringVersion description
LicenseInfoNoStringLicense information
LayerVersionNoNumberVersion number
LayerNameNoStringLayer name
StatusNoStringCurrent status of the specific layer version: Active (Normal), Publishing (In progress), PublishFailed (Failed), Deleted (Deleted)
StampNoStringStamp mark
TagsNoArray<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

FieldRequiredTypeDescription
optionsRequiredILayerOptions structureRequest parameter

ILayerOptions Structure

FieldRequiredTypeDescription
nameRequiredStringlayer name
versionRequiredNumberVersion number

3. Return Results

FieldRequiredTypeDescription
RequestIdRequiredStringRequest ID
CompatibleRuntimesRequiredArray<String>Compatible runtime
CodeSha256RequiredStringSHA256 hash of the version file in the layer
LocationRequiredStringDownload URL of the version file in the layer
AddTimeRequiredStringCreation time of the version
DescriptionRequiredStringVersion description
LicenseInfoRequiredStringLicense information
LayerVersionRequiredNumberVersion number
LayerNameRequiredStringlayer name
StatusYesStringCurrent 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

FieldRequiredTypeDescription
functionNameRequiredStringfunction name
qualifierYesStringfunction version name
versionProvisionedConcurrencyNumRequiredNumberprovisioned concurrency for the current version

3. Return Results

FieldRequiredTypeDescription
RequestIdRequiredStringRequest 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

FieldRequiredTypeDescription
functionNameRequiredStringFunction name
qualifierNoStringFunction version name. If left blank, the provisioned concurrency information for all versions of the function will be queried.

3. Return Results

FieldTypeDescription
RequestIdStringRequest ID
UnallocatedConcurrencyNumNumberRemaining configurable provisioned concurrency for the function.
AllocatedArray<IVersionProvisionedConcurrencyInfo>Details of the provisioned concurrency configuration for the function.

IVersionProvisionedConcurrencyInfo

FieldTypeDescription
AllocatedProvisionedConcurrencyNumNumberConfigured provisioned concurrency.
AvailableProvisionedConcurrencyNumNumberProvisioned concurrency
StatusStringProvisioning task status. Done indicates completed, InProgress indicates in progress, Failed indicates partially or completely failed.
StatusReasonStringTask status reason
QualifierStringVersion 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

FieldRequiredTypeDescription
functionNameRequiredStringFunction name
qualifierRequiredStringFunction version name. If left blank, the provisioned concurrency information for all versions of the function will be queried.

3. Return Results

FieldTypeDescription
RequestIdStringRequest 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

FieldRequiredTypeDescription
functionNameRequiredStringFunction name
descriptionNoStringVersion description

3. Return Results

FieldTypeDescription
RequestIdStringRequest ID
FunctionVersionStringFunction version
CodeSizeNumberCode size
MemorySizeNumberMaximum available memory
HandlerStringFunction entry
TimeoutNumberFunction timeout period
RuntimeStringRuntime
NamespaceStringFunction 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

FieldRequiredTypeDescription
functionNameRequiredStringFunction name
offsetNoNumberData offset, default value is 0
limitNoNumberReturned data length, default value is 20
orderNoNumberSpecifies the order of results: ASC (ascending) or DESC (descending)
orderByNoNumberSpecifies the field to sort the returned results by. Supported fields: AddTime, ModTime

3. Return Results

FieldTypeDescription
RequestIdStringRequest ID
TotalCountStringTotal number of function versions
FunctionVersionArray<String>List of function version names
VersionsArray<IFunctionVersion>List of function versions

IFunctionVersion

FieldTypeDescription
VersionStringFunction version name
DescriptionStringVersion description
AddTimeStringCreation time
ModTimeStringModification time
StatusStringVersion 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

FieldRequiredTypeDescription
functionNameRequiredStringFunction name
nameRequiredStringAlias name, default to '$DEFAULT'
functionVersionRequiredStringPrimary version of the alias, default to '$LATEST'
descriptionNoStringAlias description
routingConfigNoIRoutingConfigRouting configuration

IRoutingConfig

FieldRequiredTypeDescription
AdditionalVersionWeightsNoArray<IVersionWeight>Version weight configuration (gray release)
AddtionVersionMatchsNoArray<IVersionMatch>Additional version matches for rule-based routing

IVersionWeight

FieldRequiredTypeDescription
VersionRequiredStringFunction version name
WeightRequiredNumberTraffic weight for this version (0-100)

IVersionMatch

FieldRequiredTypeDescription
VersionRequiredStringFunction version name
KeyRequiredStringThe 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'
MethodRequiredStringMatching method, defaults to 'range'
ExpressionRequiredStringThe range matching rule requires: an open or closed interval description (a,b) or [a,b], where both a and b are integers.
danger

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

FieldTypeDescription
RequestIdStringRequest 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

FieldRequiredTypeDescription
functionNameRequiredStringFunction name
nameRequiredStringAlias name, default to '$DEFAULT'

3. Return Results

FieldTypeDescription
RequestIdStringRequest ID
FunctionVersionStringAlias-targeted primary version
NameStringAlias name
RoutingConfigIRoutingConfigAlias routing information
DescriptionStringDescription
AddTimeStringCreation time
ModTimeStringModification 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

Warning

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

FieldRequiredTypeDescription
limitNoNumberrange
offsetNoNumberoffset

3. Return Results

FieldRequiredTypeDescription
RequestIDRequiredStringUnique identifier of the request
TotalCountRequiredNumberTotal count
FunctionsRequiredArrayFunction list
Functions[].FunctionIdRequiredStringFunction ID
Functions[].FunctionNameRequiredStringFunction name
Functions[].NamespaceRequiredStringNamespace
Functions[].RuntimeRequiredStringRuntime
Functions[].AddTimeRequiredStringCreation time
Functions[].ModTimeRequiredStringModification 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

Deprecation Notice

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

FieldRequiredTypeDescription
optionsRequiredIFunctionLogOptionsLog query options

IFunctionLogOptions

FieldRequiredTypeDescription
nameRequiredStringFunction name
offsetNoNumberThe offset of data. Offset+Limit cannot exceed 10000.
limitNoNumberThe length of returned data. Offset+Limit cannot exceed 10000.
orderNoStringSpecifies the sort order for logs: 'asc' (ascending) or 'desc' (descending)
orderByNoStringSorts logs by a specific field. Supported fields: function_name, duration, mem_usage, start_time
startTimeNoStringThe specific date for the query, e.g., 2017-05-16 20:00:00, must be within one day of EndTime
endTimeNoStringThe specific date for the query, e.g., 2017-05-16 20:59:59, must be within one day of StartTime
requestIdNoStringThe requestId corresponding to the execution of this function

3. Return Results

FieldRequiredTypeDescription
RequestIdRequiredStringUnique identifier of the request
TotalCountRequiredStringThe total number of function logs
Data[]RequiredArrayReturn of function execution
Data[].RequestIdYesStringThe requestId corresponding to the execution of this function
Data[].FunctionNameYesStringFunction name
Data[].RetCodeYesNumberFunction execution result; 0 indicates success, any other value indicates failure
Data[].InvokeFinishedYesNumberWhether the function invocation is finished; 1 indicates finished, any other value indicates an invocation exception
Data[].StartTimeRequiredStringFunction execution start time
Data[].DurationRequiredNumberIndicates the execution duration of the function in milliseconds. Returns empty for asynchronous invocations.
Data[].BillDurationRequiredNumberIndicates the billing duration of the function in milliseconds. Returns empty for asynchronous invocations.
Data[].MemUsageRequiredNumberMemory usage during function execution in Bytes. Returns empty for asynchronous invocations.
Data[].RetMsgRequiredStringIndicates 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>

version tip

This API has been supported since v5.0.0.

2. Input Parameters

IFunctionBatchOptions

FieldRequiredTypeDescription
functionsRequiredICloudFunctionV2[]SCF configuration array, each item must contain name (function name) and triggers (trigger configuration array)
envIdNoStringEnvironment ID. If not passed, the environment from initialization will be used.
logNoBooleanwhether 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>

version tip

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

FieldRequiredTypeDescription
functionsRequiredICloudFunctionV2[]SCF configuration array, each item contains name (function name) and triggers (trigger array with name)
envIdNoStringEnvironment 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>

version tip

This API has been supported since v5.0.0.

2. Input Parameters

IAttachOptions

FieldRequiredTypeDescription
functionNameRequiredStringSCF name
layerNameRequiredStringfile layer name
layerVersionRequiredNumberfile layer version number
envIdNoStringEnvironment ID
codeSecretNoStringCode Secret for the encryption function

3. Return Results

FieldTypeDescription
RequestIdStringUnique 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>

version tip

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)

FieldRequiredTypeDescription
functionNameRequiredStringSCF name
layerNameRequiredStringfile layer name
layerVersionRequiredNumberfile layer version number
envIdNoStringEnvironment ID
codeSecretNoStringCode Secret for the encryption function

3. Return Results

FieldTypeDescription
RequestIdStringUnique 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>

version tip

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 layers after invocation. For incremental operations, use attachLayer / unAttachLayer.

2. Input Parameters

ISortOptions

FieldRequiredTypeDescription
functionNameRequiredStringSCF name
layersRequiredILayer[]Target file layer list (full)
envIdNoStringEnvironment ID

ILayer

FieldRequiredTypeDescription
LayerNameRequiredStringFile layer name
LayerVersionRequiredNumberFile layer version number

3. Return Results

FieldTypeDescription
RequestIdStringUnique 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>

version tip

This API has been supported since v5.0.0.

2. Input Parameters

ILayerDownloadOptions

FieldRequiredTypeDescription
nameRequiredStringfile layer name
versionRequiredNumberfile layer version number
destPathRequiredStringlocal storage directory, ZIP file will be saved as <destPath>/<name>-<version>.zip
forceNoBooleanreserved 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()