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.
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.
Quick Example
A typical SCF configuration example:
{
"envId": "dev-xxxx",
"functionRoot": "./functions",
"functions": [
{
"name": "app",
"timeout": 5,
"runtime": "Nodejs18.15",
"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 | Nodejs18.15 | 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 |
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 that will completely overwrite online configurations during deployment |
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 |
Runtime Environment
CloudBase SCF supports the following runtime environments:
Node.js runtime
Nodejs20.19(Public Beta)Nodejs18.15(Recommended)Nodejs16.13Nodejs14.18Nodejs12.16Nodejs10.15
Other Language Runtimes
Php8.0Php7.4Php7.2Python3.10Python3.9Python3.7Python3.6Golang1Java11Java8
- Node.js projects use the
Nodejs18.15runtime 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.
Pulling Function Configuration
Using the tcb config pull fn command can pull the configuration of deployed SCF from the cloud and save it to the local configuration file:
tcb config pull fn [name...] [options]
Command Parameters:
| Parameter | Description | Required |
|---|---|---|
fn | Module name, specify the SCF configuration to operate on | Yes |
[name...] | SCF function name(s). Supports specifying one or more function names. | No |
--all | Pull configurations of all functions in the configuration file | No |
-e, --env-id <envId> | Environment Id | No |
-o, --output <output> | Output file path, defaults to cloudbaserc.json in the current directory | No |
--stdout | Output to console instead of file | No |
--code-secret <codeSecret> | CodeSecret for code-encrypted functions | No |
--dir <dir> | Specifies the directory for inferring the configuration (when the SCF does not exist) | No |
--yes | Skip interactive confirmation and automatically overwrite existing files | No |
Command Behavior Description:
- If the SCF exists, pull the full configuration from the cloud.
- If the SCF does not exist, it will ask whether to infer the configuration from the local project.
- If the target configuration file already exists, it will intelligently merge:
- Function configurations with the same name will be asked whether to update
- Function configurations with different names will be appended to the
functionsarray
Usage Example:
# Pulling Configuration for a Single Function
tcb config pull fn myFunc
# Pulling Configuration for Multiple Functions
tcb config pull fn func1 func2 func3
# Pulling Configurations for All Functions in the Configuration File
tcb config pull fn --all
# Output to the console
tcb config pull fn func1 func2 --stdout
# Automatic confirmation mode (skip interactive confirmation)
tcb config pull fn --all --yes
# Specify output file path
tcb config pull fn myFunc -o ./config/cloudbaserc.json
Update Function Configuration
Using the tcb config update fn command can update the runtime configuration for deployed SCF.
Basic Usage
# Update configuration for the specified function (from the configuration file)
tcb config update fn <functionName>
# Update configurations for all functions in the configuration file
tcb config update fn --all
Command Parameters
| Parameter | Description | Required |
|---|---|---|
fn | Module name, specify the SCF configuration to operate on | Yes |
<functionName> | SCF function name | No |
--all | Update configurations for all functions in the configuration file | No |
-e, --env-id <envId> | environment Id | No |
--timeout <timeout> | Function timeout period (in seconds), range: 1-900 | No |
--memory <memory> | Function memory size (MB), range: 64-3072 | No |
--env <key=value> | Set environment variables, can be used multiple times | No |
--env-mode <mode> | Environment variable update mode: merge (merge) or overwrite (overwrite) | No |
--yes | Skip interactive confirmation and directly execute | No |
Quick Update via CLI Parameters
In addition to reading from the configuration file, you can also directly update individual configuration items via CLI parameters:
# Updating Timeout Period
tcb config update fn myFunc --timeout 60 -e envId --yes
# Updating Memory Size
tcb config update fn myFunc --memory 512 -e envId --yes
# Update Environment Variables (Merge Mode, Retain Existing Variables)
tcb config update fn myFunc --env DB_HOST=127.0.0.1 --env-mode merge -e envId --yes
# Update Environment Variables (Overwrite Mode, Replace All Variables)
tcb config update fn myFunc --env DB_HOST=127.0.0.1 --env-mode overwrite -e envId --yes
# Batch Updating Multiple Configurations
tcb config update fn myFunc --timeout 30 --memory 256 --env NODE_ENV=production -e envId --yes
Configuration Priority
Configuration updates follow the following priority (from highest to lowest):
CLI parameters > configuration file > existing cloud configuration
- When using
--env-mode overwrite, the environment variables in the configuration file will completely overwrite the cloud configurations - When using
--env-mode merge, only the designated environment variables are updated, while other variables are retained - It is recommended to include the
--yesparameter in automated scripts to skip interactive confirmation
Usage Example
# Update app Function Configuration from Configuration File
tcb config update fn app
# Update configurations for all functions (skip confirmation)
tcb config update fn --all --yes
# Quickly Updating an Individual Configuration Item
tcb config update fn app --timeout 60 --yes
Compare Function Configurations
The tcb config diff fn command can be used to compare the differences between the local configuration file and the cloud function configurations.
Basic Usage
# Compare Designated Function Configurations
tcb config diff fn <functionName>
# Compare Configurations for All Functions in the Configuration File
tcb config diff fn --all
Command Parameters
| Parameter | Description | Required |
|---|---|---|
fn | Module name, specify the SCF configuration to operate on | Yes |
<functionName> | SCF function name | No |
--all | Compare configurations of all functions in the configuration file | No |
-e, --env-id <envId> | Environment Id | No |
Usage Example
# Configuration Differences of a Single Function
tcb config diff fn myFunc -e envId
# Configuration Differences of All Functions
tcb config diff fn --all -e envId
Output Example
The command outputs the configuration comparison results in a tabular format:
Comparing [myFunc] Configuration Comparison
| Configuration Item | Cloud Value | Local Value | Change |
|------------|---------|---------|------|
| timeout | 5 | 60 | ~ |
| memorySize | 256 | 512 | ~ |
| role | - | SCF_CLS | ~ |
| Function Type | HTTP | HTTP | |
Change Flag Description:
~: Configuration item changed- Empty: Configuration item unchanged
- Check configuration changes before deployment to avoid accidental overwrites
- Troubleshoot configuration inconsistencies
- Verify configuration changes during code review
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": "Nodejs18.15", // Runtime environment
"memorySize": 256, // Memory size (MB), range: 64-3072
"installDependency": true, // Automatically install dependencies in the cloud (only for Node.js)
// Environment variables (completely overwrite cloud configurations during deployment)
"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": "Nodejs18.15",
"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": "Nodejs18.15",
"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_CLSFullAccess",
"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 - Environment variables will completely overwrite cloud configurations during deployment; ensure that all required variables are included.
Important Notes
Environment Variable Overwrite Rules
The envVariables configuration during deployment will completely overwrite existing cloud-based environment variable configurations, rather than performing incremental merging.
Example Scenario:
- 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)
Recommended Practices:
If you have manually configured environment variables in the console, please ensure these configurations are also included in cloudbaserc.json, otherwise they will be lost after deployment.