Skip to main content

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.

Configuration Flattening

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

ConfigurationRequiredTypeDefaultDescription
functionRootNoString-Root directory for all cloud functions, if dir is not specified, the function deployment path is functionRoot/name
nameYesString-Cloud function name, the identifier after function deployment
typeNoStringEventFunction type, options: Event (event-triggered function), HTTP (HTTP cloud function)
dirNoString-Folder path where the cloud function code is located, when specified it will be used as the function deployment path
handlerNoStringindex.mainFunction handler method name, format: filename.functionname
Java runtime must specify full path, e.g., package.Class::mainHandler
runtimeNoStringNodejs18.15Runtime environment, see Runtime Environment
timeoutNoNumber5Function timeout in seconds, range 1-900
memorySizeNoNumber256Function memory size (MB), range 64-3072
protocolTypeNoString-Access protocol for HTTP functions, currently supports WebSocket protocol, value is WS
protocolParamsNoObject-Protocol parameter configuration, see WebSocket Configuration
instanceConcurrencyConfigNoObject-Instance concurrency configuration, see Concurrency Configuration
imageConfigNoObject-Container image deployment configuration, see Image Configuration

Code and Dependency Configuration

ConfigurationRequiredTypeDefaultDescription
ignoreNoString/Array-Files or directories to ignore during deployment, supports glob patterns
Recommended to ignore node_modules, .git, etc.
installDependencyNoBooleanfalseWhether to automatically install dependencies in the cloud (Node.js runtime only)
codeSecretNoString-Code encryption key, 36 characters of uppercase/lowercase letters and numbers

Advanced Configuration

ConfigurationRequiredTypeDefaultDescription
envVariablesNoObject-Environment variable key-value pairs, will completely overwrite online configuration during deployment
vpcNoObject-VPC configuration, see VPC Configuration
triggersNoArray-Trigger configuration, see Trigger Configuration
paramsNoObject-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.13
  • Nodejs14.18
  • Nodejs12.16
  • Nodejs10.15

Other Language Runtimes

  • Php8.0
  • Php7.4
  • Php7.2
  • Python3.10
  • Python3.9
  • Python3.7
  • Python3.6
  • Golang1
  • Java11
  • Java8
Runtime Notes
  • Node.js projects default to Nodejs18.15 runtime, the runtime configuration can be omitted
  • Non-Node.js runtimes like PHP, Java must explicitly specify the runtime value
  • After enabling codeSecret code 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:

ConfigurationRequiredTypeDescription
nameYesStringTrigger name, maximum 60 characters
Supported characters: a-z, A-Z, 0-9, - and _, must start with a letter
typeYesStringTrigger type, currently only supports timer (scheduled trigger)
configYesStringTrigger configuration, scheduled triggers use standard Cron expressions

Configuration Example:

{
"triggers": [
{
"name": "myTrigger",
"type": "timer",
"config": "0 0 2 1 * * *"
}
]
}
Trigger Limitations

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:

ConfigurationRequiredTypeDescription
vpcIdYesStringVPC network ID
subnetIdYesStringVPC subnet ID

Configuration Example:

{
"vpc": {
"vpcId": "vpc-xxx",
"subnetId": "subnet-xxx"
}
}

WebSocket Configuration

WebSocket protocol parameter configuration, used with protocolType: "WS":

ConfigurationRequiredTypeDescription
wsParams.idleTimeOutNoNumberWebSocket 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:

ConfigurationRequiredTypeDescription
maxConcurrencyNoNumberMaximum concurrency per instance, range 2~100
dynamicEnabledNoStringEnable 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.

ConfigurationRequiredTypeDescription
imageTypeYesStringImage type: enterprise or personal
imageUriYesStringImage address, format: registry/namespace/image:tag
registryIdNoStringEnterprise image registry ID, required for enterprise type
imagePortNoNumberContainer listening port, default 9000
entryPointNoStringContainer startup command
commandListNoString[]Startup command list
argsListNoString[]Startup argument list
containerImageAccelerateNoBooleanEnable image acceleration

Image Type Description:

TypeDescriptionregistryId
personalPersonal image registryNot required
enterpriseEnterprise 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 Deployment Notes
  1. Image address format: Must include tag (e.g., :latest or :v1.0.0)
  2. Port configuration: Default listening port is 9000, customizable via imagePort
  3. Enterprise images: Must specify registryId, otherwise deployment will fail
  4. Code download restriction: Functions deployed via image cannot use tcb fn code download
  5. scf_bootstrap skip: Image deployment skips scf_bootstrap check 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:

ParameterDescriptionRequired
fnModule name, specifies operating on cloud function configurationYes
[name...]Cloud function name(s), supports one or multiple function namesNo
--allPull configuration for all functions in config fileNo
-e, --envId <envId>Environment IdNo
-o, --output <output>Output file path, defaults to cloudbaserc.json in current directoryNo
--stdoutOutput to console instead of fileNo
--code-secret <codeSecret>CodeSecret for code-encrypted functionsNo
--dir <dir>Specify directory for inferring config (when cloud function doesn't exist)No
--yesSkip interactive confirmation, auto-overwrite existing filesNo

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 functions array

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.json and 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.
Notice

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
}
}
]
}
Configuration Notes
  • jsonc format supports comments; remove comments or use standard JSON format in actual use
  • HTTP functions must set type to HTTP
  • 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.