Configuration File - Cloud Functions
In the CloudBase CLI configuration file cloudbaserc.json, you can define multiple cloud function configuration items through the functions array. These configuration items control the deployment behavior and runtime characteristics of functions.
Since CLI version 0.6.0, the config option within the functions array has been flattened. All configuration items previously nested in config can now be written directly in the functions array items for more convenient usage.
Quick Example
A typical cloud function configuration example:
{
"envId": "dev-xxxx",
"functionRoot": "./functions",
"functions": [
{
"name": "app",
"timeout": 5,
"runtime": "Nodejs18.15",
"installDependency": true,
"handler": "index.main"
}
]
}
Configuration Items Details
Basic Configuration
| Configuration | Required | Type | Default | Description |
|---|---|---|---|---|
functionRoot | No | String | - | Root directory for all cloud functions, if dir is not specified, the function deployment path is functionRoot/name |
name | Yes | String | - | Cloud function name, the identifier after function deployment |
type | No | String | Event | Function type, options: Event (event-triggered function), HTTP (HTTP cloud function) |
dir | No | String | - | Folder path where the cloud function code is located, when specified it will be used as the function deployment path |
handler | No | String | index.main | Function handler method name, format: filename.functionnameJava runtime must specify full path, e.g., package.Class::mainHandler |
runtime | No | String | Nodejs18.15 | Runtime environment, see Runtime Environment |
timeout | No | Number | 5 | Function timeout in seconds, range 1-900 |
memorySize | No | Number | 256 | Function memory size (MB), range 64-3072 |
protocolType | No | String | - | Access protocol for HTTP functions, currently supports WebSocket protocol, value is WS |
protocolParams | No | Object | - | Protocol parameter configuration, see WebSocket Configuration |
instanceConcurrencyConfig | No | Object | - | Instance concurrency configuration, see Concurrency Configuration |
imageConfig | No | Object | - | Container image deployment configuration, see Image Configuration |
Code and Dependency Configuration
| Configuration | Required | Type | Default | Description |
|---|---|---|---|---|
ignore | No | String/Array | - | Files or directories to ignore during deployment, supports glob patterns Recommended to ignore node_modules, .git, etc. |
installDependency | No | Boolean | false | Whether to automatically install dependencies in the cloud (Node.js runtime only) |
codeSecret | No | String | - | Code encryption key, 36 characters of uppercase/lowercase letters and numbers |
Advanced Configuration
| Configuration | Required | Type | Default | Description |
|---|---|---|---|---|
envVariables | No | Object | - | Environment variable key-value pairs, will completely overwrite online configuration during deployment |
vpc | No | Object | - | VPC configuration, see VPC Configuration |
triggers | No | Array | - | Trigger configuration, see Trigger Configuration |
params | No | Object | - | Default input parameters when CLI invokes cloud function |
Runtime Environment
CloudBase cloud functions support the following runtime environments:
Node.js Runtimes
Nodejs20.19(In beta)Nodejs18.15(Recommended)Nodejs16.13Nodejs14.18Nodejs12.16Nodejs10.15
Other Language Runtimes
Php8.0Php7.4Php7.2Python3.10Python3.9Python3.7Python3.6Golang1Java11Java8
- Node.js projects default to
Nodejs18.15runtime, theruntimeconfiguration can be omitted - Non-Node.js runtimes like PHP, Java must explicitly specify the
runtimevalue - After enabling
codeSecretcode encryption, cloud function source code cannot be viewed in the Mini Program IDE or Tencent Cloud Console
Trigger Configuration
Trigger configuration items define automatic trigger rules for cloud functions:
| Configuration | Required | Type | Description |
|---|---|---|---|
name | Yes | String | Trigger name, maximum 60 characters Supported characters: a-z, A-Z, 0-9, - and _, must start with a letter |
type | Yes | String | Trigger type, currently only supports timer (scheduled trigger) |
config | Yes | String | Trigger configuration, scheduled triggers use standard Cron expressions |
Configuration Example:
{
"triggers": [
{
"name": "myTrigger",
"type": "timer",
"config": "0 0 2 1 * * *"
}
]
}
Currently, each cloud function only supports configuring one trigger. For detailed trigger management, refer to Trigger Documentation.
VPC Configuration
VPC configuration items deploy cloud functions into specified VPC networks:
| Configuration | Required | Type | Description |
|---|---|---|---|
vpcId | Yes | String | VPC network ID |
subnetId | Yes | String | VPC subnet ID |
Configuration Example:
{
"vpc": {
"vpcId": "vpc-xxx",
"subnetId": "subnet-xxx"
}
}
WebSocket Configuration
WebSocket protocol parameter configuration, used with protocolType: "WS":
| Configuration | Required | Type | Description |
|---|---|---|---|
wsParams.idleTimeOut | No | Number | WebSocket idle timeout in seconds, range 10~7200 |
Configuration Example:
{
"protocolType": "WS",
"protocolParams": {
"wsParams": {
"idleTimeOut": 110
}
}
}
Concurrency Configuration
Multi-concurrency configuration for single instance, only supported for HTTP cloud functions:
| Configuration | Required | Type | Description |
|---|---|---|---|
maxConcurrency | No | Number | Maximum concurrency per instance, range 2~100 |
dynamicEnabled | No | String | Enable smart dynamic concurrency. FALSE for static concurrency, empty string '' to cancel multi-concurrency config |
Configuration Example:
{
"instanceConcurrencyConfig": {
"maxConcurrency": 40,
"dynamicEnabled": "FALSE"
}
}
Image Configuration
Cloud functions support container image deployment, suitable for scenarios requiring custom runtime environments, non-standard languages, or complex system library dependencies.
| Configuration | Required | Type | Description |
|---|---|---|---|
imageType | Yes | String | Image type: enterprise or personal |
imageUri | Yes | String | Image address, format: registry/namespace/image:tag |
registryId | No | String | Enterprise image registry ID, required for enterprise type |
imagePort | No | Number | Container listening port, default 9000 |
entryPoint | No | String | Container startup command |
commandList | No | String[] | Startup command list |
argsList | No | String[] | Startup argument list |
containerImageAccelerate | No | Boolean | Enable image acceleration |
Image Type Description:
| Type | Description | registryId |
|---|---|---|
personal | Personal image registry | Not required |
enterprise | Enterprise image registry (TCR) | Required |
Configuration Example (Personal):
{
"functions": [
{
"name": "image-function",
"timeout": 30,
"memorySize": 512,
"imageConfig": {
"imageType": "personal",
"imageUri": "<registry-domain>/your-namespace/your-image:tag",
"imagePort": 9000
}
}
]
}
Configuration Example (Enterprise):
{
"functions": [
{
"name": "enterprise-func",
"timeout": 60,
"memorySize": 1024,
"imageConfig": {
"imageType": "enterprise",
"imageUri": "<registry-domain>/namespace/app:v1.0.0",
"registryId": "tcr-xxxxxxxx",
"imagePort": 8080,
"containerImageAccelerate": true,
"commandList": ["/app/start.sh"],
"argsList": ["--config", "/app/config.json"]
}
}
]
}
- Image address format: Must include tag (e.g.,
:latestor:v1.0.0) - Port configuration: Default listening port is 9000, customizable via
imagePort - Enterprise images: Must specify
registryId, otherwise deployment will fail - Code download restriction: Functions deployed via image cannot use
tcb fn code download - scf_bootstrap skip: Image deployment skips
scf_bootstrapcheck for Web functions
Pull Function Configuration
Use the tcb config pull fn command to pull configuration of deployed cloud functions from the cloud and save to local config file:
tcb config pull fn [name...] [options]
Command Parameters:
| Parameter | Description | Required |
|---|---|---|
fn | Module name, specifies operating on cloud function configuration | Yes |
[name...] | Cloud function name(s), supports one or multiple function names | No |
--all | Pull configuration for all functions in config file | No |
-e, --envId <envId> | Environment Id | No |
-o, --output <output> | Output file path, defaults to cloudbaserc.json in current directory | No |
--stdout | Output to console instead of file | No |
--code-secret <codeSecret> | CodeSecret for code-encrypted functions | No |
--dir <dir> | Specify directory for inferring config (when cloud function doesn't exist) | No |
--yes | Skip interactive confirmation, auto-overwrite existing files | No |
Command Behavior:
- If cloud function exists, pulls complete configuration from cloud
- If cloud function doesn't exist, prompts whether to infer configuration from local project
- If target config file already exists, smart merge is performed:
- Same-name function config will prompt for update confirmation
- Different-name function config will be appended to
functionsarray
Usage Examples:
# Pull single function config
tcb config pull fn myFunc
# Pull multiple function configs
tcb config pull fn func1 func2 func3
# Pull all functions in config file
tcb config pull fn --all
# Output to console
tcb config pull fn func1 func2 --stdout
# Auto-confirm 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
Use the tcb fn config update command to update runtime configuration of deployed cloud functions:
# Update configuration for specified function
tcb fn config update <functionName>
# Update configuration for all functions in config file
tcb fn config update
Command Behavior:
- CLI reads function configuration from
cloudbaserc.jsonand syncs to the cloud - All configuration items in the config file will be updated, individual item updates are not supported yet
- Updatable configurations include: timeout, environment variables, memory size, VPC network, dependency installation, etc.
When using this command, configuration in the config file will completely overwrite cloud configuration. Ensure the config file contains all configuration items you want to retain.
Usage Examples:
# Update configuration for app function
tcb fn config update app
# Update configuration for all functions
tcb fn config update
Complete Configuration Example
Below is a complete example with all commonly used configuration items:
{
// Environment ID (required)
"envId": "dev-xxxx",
// Cloud functions root directory, defaults to ./functions
"functionRoot": "./functions",
// Cloud functions configuration array
"functions": [
// ========== Regular Cloud Function (Event-triggered) ==========
{
"name": "app", // Function name (required)
"handler": "index.main", // Entry function, format: filename.functionname
"timeout": 5, // Timeout (seconds), range 1-900
"runtime": "Nodejs18.15", // Runtime environment
"memorySize": 256, // Memory size (MB), range 64-3072
"installDependency": true, // Auto-install dependencies in cloud (Node.js only)
// Environment variables (completely overwrites cloud config during deployment)
"envVariables": {
"NODE_ENV": "production",
"DB_HOST": "localhost"
},
// VPC private network configuration
"vpc": {
"vpcId": "vpc-xxx",
"subnetId": "subnet-xxx"
},
// Scheduled trigger configuration
"triggers": [
{
"name": "dailyTask", // Trigger name
"type": "timer", // Type: timer (scheduled trigger)
"config": "0 0 2 * * * *" // Cron expression: daily at 2 AM
}
],
// Files to ignore during deployment
"ignore": [
"*.md",
".git",
"node_modules",
"node_modules/**/*",
"test/**/*"
]
},
// ========== HTTP Cloud Function (Web Service) ==========
{
"name": "webApi",
"type": "HTTP", // HTTP function must be set to "HTTP"
"handler": "index.main",
"timeout": 60,
"runtime": "Nodejs18.15",
"memorySize": 512,
// Single instance multi-concurrency config (HTTP functions only)
"instanceConcurrencyConfig": {
"maxConcurrency": 40, // Max 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 (seconds), range 10-7200
}
}
},
// ========== Image Deployment Function ==========
{
"name": "imageFunc",
"type": "HTTP",
"handler": "index.main",
"timeout": 60,
"runtime": "Nodejs18.15",
"memorySize": 1024,
// Image configuration
"imageConfig": {
"imageType": "personal", // personal | enterprise
"imageUri": "ccr.ccs.tencentyun.com/your-namespace/your-image:v1.0.0",
"imagePort": 9000 // Container listening port, default 9000
}
}
]
}
jsoncformat supports comments; remove comments or use standard JSON format in actual use- HTTP functions must set
typetoHTTP - Environment variables completely overwrite cloud config during deployment; ensure all required variables are included
Important Notes
Environment Variable Overwrite Rules
During deployment, the envVariables configuration will completely overwrite existing cloud environment variable configuration, not merge incrementally.
Example Scenario:
- Cloud existing environment variables:
{DB_HOST: "xxx", API_KEY: "xxx"} - Config file only has:
{DB_HOST: "yyy"} - After deployment, cloud environment variables become:
{DB_HOST: "yyy"}(API_KEY is deleted)
Recommended Practice:
If you manually configured environment variables in the console, ensure these configurations are also included in cloudbaserc.json, otherwise they will be lost after deployment.