Configuration File - SCF
In the CloudBase CLI configuration file cloudbaserc.json, you can define configuration items for multiple SCFs via the functions array. These configuration items control the deployment behavior and runtime characteristics of the SCFs.
This article only describes the
functionsconfiguration fields; for deployment steps, see Deploy SCF, and for pulling, updating, and comparing configurations, see Configuration Operations.
Starting from CLI version 0.6.0, the config option under functions has been flattened. All configuration items originally nested under config can now be written directly in the functions array items, simplifying usage.
Field Quick Reference
All configuration fields of the functions array items are summarized by group below. Click a group name to jump to the corresponding section:
| Configuration Group | Fields |
|---|---|
| Basic Configuration Items | functionRoot, name, type, dir, handler, runtime, timeout, memorySize, protocolType, protocolParams, instanceConcurrencyConfig, imageConfig, buildStrategy |
| Code and Dependency Configuration | ignore, installDependency, codeSecret |
| Advanced Configuration | envVariables, vpc, triggers, params, role, clsLogsetId, clsTopicId, public, gatewayPath |
| Runtime Environment | List of supported runtime versions |
| Trigger Configuration | name, type, config |
| VPC Configuration | vpcId, subnetId |
| WebSocket Configuration | wsParams.idleTimeOut |
| Concurrency Configuration | maxConcurrency, dynamicEnabled |
| Image Configuration | imageType, imageUri, registryId, imagePort, entryPoint, commandList, argsList, containerImageAccelerate |
Quick Example
A typical SCF configuration example:
{
"envId": "dev-xxxx",
"functionRoot": "./functions",
"functions": [
{
"name": "app",
"timeout": 5,
"runtime": "Nodejs20.19",
"installDependency": true,
"handler": "index.main"
}
]
}
Detailed Explanation of Configuration Items
Basic Configuration Items
| Configuration Item | Required | Type | Default Value | Description |
|---|---|---|---|---|
functionRoot | No | String | - | The root directory for all SCFs. If dir is not specified, the deployment path of the function is functionRoot/name. |
name | Yes | String | - | SCF name, which serves as the identifier after deployment |
type | No | String | Event | Function type. Valid values: Event (event-triggered function) or HTTP (HTTP-triggered SCF) |
dir | No | String | - | The folder path where the SCF code resides. When specified, it will be used as the deployment path of the function. |
handler | No | String | index.main | Function handler name, in the format filename.functionnameFor Java runtime, the full path must be specified, such as package.Class::mainHandler |
runtime | No | String | Nodejs20.19 | Runtime environment. For details, see Runtime Environment |
timeout | No | Number | 5 | Function timeout period, value range: 1-900 seconds |
memorySize | No | Number | 256 | Function memory size (MB), value range: 64-3072 |
protocolType | No | String | - | Access protocols supported by HTTP functions. Currently supports the WebSocket protocol with the value WS |
protocolParams | No | Object | - | Protocol parameter configuration. See details in WebSocket configuration |
instanceConcurrencyConfig | No | Object | - | Instance concurrency configuration. See details in Concurrency configuration |
imageConfig | No | Object | - | Image deployment configuration. See details in Image configuration |
buildStrategy | No | String | zip | HTTP function deployment strategy (declarative deployment). Valid values: zip (code package) / image (existing image) / cloud (cloud image build) / local (local image build). See Image configuration for details |
Code and Dependency Configuration
| Configuration Item | Required | Type | Default Value | Description |
|---|---|---|---|---|
ignore | No | String/Array | - | Files or directories to ignore during deployment, supporting glob pattern matching It is recommended to ignore node_modules, .git, etc. |
installDependency | No | Boolean | false | whether to automatically install dependency packages in the cloud (only supported for Node.js runtime) |
codeSecret | No | String | - | Code encryption key, consisting of 36 uppercase and lowercase letters and numbers. |
Advanced Configuration
| Configuration Item | Required | Type | Default Value | Description |
|---|---|---|---|---|
envVariables | No | Object | - | Environment variable key-value pairs. The update behavior during deployment depends on the CLI version. See Environment Variable Update Rules |
vpc | No | Object | - | VPC configuration. See details in VPC configuration |
triggers | No | Array | - | Trigger configuration. See details in Trigger configuration |
params | No | Object | - | Default input parameters for CLI invocation of SCF |
role | No | String | - | Role name bound to the function, used for scenarios such as log delivery |
clsLogsetId | No | String | - | CLS logset ID, which requires manual configuration during image deployment |
clsTopicId | No | String | - | CLS log topic ID, which requires manual configuration during image deployment |
public | No | Boolean | false | Whether to allow anonymous access (HTTP functions only). When true, anonymous access is automatically enabled after deployment (OPA Rego), allowing invocation via URL without login |
gatewayPath | No | String | - | Gateway path (HTTP functions only, starting with /). After deployment, the API gateway route is automatically converged, equivalent to the declarative gateway.routes |
Runtime Environment
CloudBase SCF supports the following runtime environments:
Node.js runtime
Nodejs24.11(Public Beta)Nodejs22.21(Public Beta)Nodejs20.19(Recommended)Nodejs18.15Nodejs16.13
Other Language Runtimes
Php8.0Php7.4Python3.11Python3.10Python3.9Python3.7Go1Java11
For complete runtime environment information, see Runtime Environment Support.
- Node.js projects use the
Nodejs20.19runtime by default, so theruntimeconfiguration can be omitted. - For non-Node.js runtimes such as PHP and Java, the
runtimevalue must be explicitly specified. - After enabling
codeSecretcode encryption, you will not be able to view the SCF source code in the Mini Program IDE or Tencent Cloud console.
Trigger Configuration
Trigger configuration items are used to define the automatic triggering rules for SCF:
| Configuration Item | Required | Type | Description |
|---|---|---|---|
name | Required | String | Trigger name, up to 60 characters Supported characters: a-z, A-Z, 0-9, -, and _, must start with a letter |
type | Required | String | Trigger type. Currently only supports timer (timer trigger) |
config | Required | String | Trigger configuration. Timer triggers use standard Cron expressions |
Configuration Example:
{
"triggers": [
{
"name": "myTrigger",
"type": "timer",
"config": "0 0 2 1 * * *"
}
]
}
Currently, each SCF supports only one trigger configuration. For detailed trigger management, see Trigger Documentation.
VPC Configuration
VPC configuration items are used to deploy SCF to a specified VPC network:
| Configuration Item | Required | Type | Description |
|---|---|---|---|
vpcId | Required | String | VPC network ID |
subnetId | Required | String | VPC subnet ID |
Configuration Example:
{
"vpc": {
"vpcId": "vpc-xxx",
"subnetId": "subnet-xxx"
}
}
WebSocket Configuration
WebSocket protocol parameter configuration must be used with protocolType: "WS":
| Configuration Item | Required | Type | Description |
|---|---|---|---|
wsParams.idleTimeOut | No | Number | WebSocket idle timeout (seconds), value range: 10~7200 |
Configuration Example:
{
"protocolType": "WS",
"protocolParams": {
"wsParams": {
"idleTimeOut": 110
}
}
}
Concurrency Configuration
Single-instance multi-concurrency configuration is supported only for HTTP SCF:
| Configuration Item | Required | Type | Description |
|---|---|---|---|
maxConcurrency | No | Number | Maximum concurrency per instance, value range: 2~100 |
dynamicEnabled | No | String | Whether to enable intelligent dynamic concurrency. FALSE indicates static concurrency, an empty string '' disables multi-concurrency configuration |
Configuration Example:
{
"instanceConcurrencyConfig": {
"maxConcurrency": 40,
"dynamicEnabled": "FALSE"
}
}
Image Configuration
SCF supports deployment via container images, which is suitable for scenarios requiring custom runtime environments, non-standard languages, or complex system library dependencies.
| Configuration Item | Required | Type | Description |
|---|---|---|---|
imageType | Required | String | Image type: enterprise (enterprise edition) or personal (personal edition) |
imageUri | Required | String | Image URI, format: registry/namespace/image:tag |
registryId | No | String | Enterprise edition image repository ID, required for enterprise edition |
imagePort | No | Number | Container listening port, defaults to 9000 |
entryPoint | No | String | Container startup command |
commandList | No | String[] | Startup command list |
argsList | No | String[] | Startup parameters list |
containerImageAccelerate | No | Boolean | whether to enable image acceleration |
Image Type Description:
| Type | Description | registryId |
|---|---|---|
personal | Personal Edition Image Repository | Not required |
enterprise | Enterprise Edition Image Repository (TCR) | Required |
Configuration Example (Personal Edition):
{
"functions": [
{
"name": "image-function",
"timeout": 30,
"memorySize": 512,
"imageConfig": {
"imageType": "personal",
"imageUri": "<access domain>/your-namespace/your-image:tag",
"imagePort": 9000
}
}
]
}
Configuration Example (Enterprise Edition):
{
"functions": [
{
"name": "enterprise-func",
"timeout": 60,
"memorySize": 1024,
"imageConfig": {
"imageType": "enterprise",
"imageUri": "<access domain>/namespace/app:v1.0.0",
"registryId": "tcr-xxxxxxxx",
"imagePort": 8080,
"containerImageAccelerate": true,
"commandList": ["/app/start.sh"],
"argsList": ["--config", "/app/config.json"]
}
}
]
}
- Image URI Format: must include a tag (tag), such as
:latestor:v1.0.0 - Port Configuration: Listens on the 9000 port by default, can be customized via
imagePort - Enterprise Edition Image: must specify
registryId, otherwise the deployment will fail - Code Download Limitation: Functions deployed via images cannot use
tcb fn code downloadto download code. - scf_bootstrap Skip: The
scf_bootstrapcheck for Web functions will be skipped during image deployment.
Complete Configuration Example
Here is a complete example containing all common configuration items:
{
// Environment ID (required)
"envId": "dev-xxxx",
// SCF root directory, default is ./functions
"functionRoot": "./functions",
// SCF configuration array
"functions": [
// ========== Regular SCF (event-triggered) ==========
{
"name": "app", // Function name (required)
"handler": "index.main", // Entry function, format: filename.functionname
"timeout": 5, // Timeout period (in seconds), range: 1-900
"runtime": "Nodejs20.19", // Runtime environment
"memorySize": 256, // Memory size (MB), range: 64-3072
"installDependency": true, // Automatically install dependencies in the cloud (only for Node.js)
// Environment variables (update behavior during deployment depends on the CLI version; see "Environment Variable Update Rules")
"envVariables": {
"NODE_ENV": "production",
"DB_HOST": "localhost"
},
// VPC private network configuration
"vpc": {
"vpcId": "vpc-xxx",
"subnetId": "subnet-xxx"
},
// Timer Trigger Configuration
"triggers": [
{
"name": "dailyTask", // Trigger name
"type": "timer", // Type: timer (scheduled trigger)
"config": "0 0 2 * * * *" // Cron expression: 2:00 AM daily
}
],
// Files to ignore during deployment
"ignore": [
"*.md",
".git",
"node_modules",
"node_modules/**/*",
"test/**/*"
]
},
// ========== HTTP-triggered SCF (Web Service) ==========
{
"name": "webApi",
"type": "HTTP", // For HTTP functions, this must be set to "HTTP"
"handler": "index.main",
"timeout": 60,
"runtime": "Nodejs20.19",
"memorySize": 512,
// Single-instance multi-concurrency configuration (supported only for HTTP functions)
"instanceConcurrencyConfig": {
"maxConcurrency": 40, // Maximum concurrency per instance, range 2-100
"dynamicEnabled": "FALSE" // FALSE: static concurrency
},
"envVariables": {
"NODE_ENV": "production"
}
},
// ========== WebSocket Function ==========
{
"name": "wsHandler",
"type": "HTTP",
"handler": "index.main",
"timeout": 900,
"runtime": "Nodejs20.19",
"memorySize": 256,
"protocolType": "WS", // enable WebSocket protocol
"protocolParams": {
"wsParams": {
"idleTimeOut": 600 // Idle timeout (in seconds), range: 10-7200
}
}
},
// ========== Image Deployment Function ==========
{
"name": "imageFunc",
"type": "HTTP",
"timeout": 60,
"memorySize": 1024,
// Image configuration (handler and runtime are not required for image deployment)
"imageConfig": {
"imageType": "personal", // personal: Personal Edition; enterprise: Enterprise Edition
"imageUri": "<access domain>/your-namespace/your-image:v1.0.0",
"imagePort": 9000 // Container listening port, defaults to 9000
},
// Log configuration (image deployment requires manual configuration)
"role": "SCF_CLSWriteOnly",
"clsLogsetId": "your-logset-id",
"clsTopicId": "your-topic-id"
}
]
}
- The
jsoncformat supports comments; in actual use, comments need to be removed or the standard JSON format should be used. - For HTTP functions, set
typetoHTTP - The update behavior of environment variables during deployment depends on the CLI version; see the "Environment Variable Update Rules" section.
Important Notes
Environment Variable Update Rules
The update behavior of the envVariables configuration during deployment depends on the CLI version:
@cloudbase/cli 2.12.0 and later
During deployment, you can choose to incrementally update (merge) or overwrite environment variables.
@cloudbase/cli earlier than 2.12.0
The environment variable configuration in cloudbaserc.json will completely overwrite the environment variables already configured online, rather than performing incremental merging.
If you are using a version earlier than 2.12.0 and have manually configured environment variables in the console, please ensure these configurations are also included in cloudbaserc.json, otherwise the original environment variables will be lost after deployment.
Overwrite Scenario Example (versions earlier than 2.12.0):
- Environment variables configured in the cloud:
{DB_HOST: "xxx", API_KEY: "xxx"} - The configuration file contains only:
{DB_HOST: "yyy"} - After deployment, the cloud-based environment variables become:
{DB_HOST: "yyy"}(API_KEY is removed)