Skip to main content

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.

Configuration Flattening

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 ItemRequiredTypeDefault ValueDescription
functionRootNoString-The root directory for all SCFs. If dir is not specified, the deployment path of the function is functionRoot/name.
nameYesString-SCF name, which serves as the identifier after deployment
typeNoStringEventFunction type. Valid values: Event (event-triggered function) or HTTP (HTTP-triggered SCF)
dirNoString-The folder path where the SCF code resides. When specified, it will be used as the deployment path of the function.
handlerNoStringindex.mainFunction handler name, in the format filename.functionname
For Java runtime, the full path must be specified, such as package.Class::mainHandler
runtimeNoStringNodejs18.15Runtime environment. For details, see Runtime Environment
timeoutNoNumber5Function timeout period, value range: 1-900 seconds
memorySizeNoNumber256Function memory size (MB), value range: 64-3072
protocolTypeNoString-Access protocols supported by HTTP functions. Currently supports the WebSocket protocol with the value WS
protocolParamsNoObject-Protocol parameter configuration. See details in WebSocket configuration
instanceConcurrencyConfigNoObject-Instance concurrency configuration. See details in Concurrency configuration
imageConfigNoObject-Image deployment configuration. See details in Image configuration

Code and Dependency Configuration

Configuration ItemRequiredTypeDefault ValueDescription
ignoreNoString/Array-Files or directories to ignore during deployment, supporting glob pattern matching
It is recommended to ignore node_modules, .git, etc.
installDependencyNoBooleanfalsewhether to automatically install dependency packages in the cloud (only supported for Node.js runtime)
codeSecretNoString-Code encryption key, consisting of 36 uppercase and lowercase letters and numbers.

Advanced Configuration

Configuration ItemRequiredTypeDefault ValueDescription
envVariablesNoObject-Environment variable key-value pairs that will completely overwrite online configurations during deployment
vpcNoObject-VPC configuration. See details in VPC configuration
triggersNoArray-Trigger configuration. See details in Trigger configuration
paramsNoObject-Default input parameters for CLI invocation of SCF
roleNoString-Role name bound to the function, used for scenarios such as log delivery
clsLogsetIdNoString-CLS logset ID, which requires manual configuration during image deployment
clsTopicIdNoString-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.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 use the Nodejs18.15 runtime by default, so the runtime configuration can be omitted.
  • For non-Node.js runtimes such as PHP and Java, the runtime value must be explicitly specified.
  • After enabling codeSecret code 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 ItemRequiredTypeDescription
nameRequiredStringTrigger name, up to 60 characters
Supported characters: a-z, A-Z, 0-9, -, and _, must start with a letter
typeRequiredStringTrigger type. Currently only supports timer (timer trigger)
configRequiredStringTrigger 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 ItemRequiredTypeDescription
vpcIdRequiredStringVPC network ID
subnetIdRequiredStringVPC subnet ID

Configuration Example:

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

WebSocket Configuration

WebSocket protocol parameter configuration must be used with protocolType: "WS":

Configuration ItemRequiredTypeDescription
wsParams.idleTimeOutNoNumberWebSocket 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 ItemRequiredTypeDescription
maxConcurrencyNoNumberMaximum concurrency per instance, value range: 2~100
dynamicEnabledNoStringWhether 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 ItemRequiredTypeDescription
imageTypeRequiredStringImage type: enterprise (enterprise edition) or personal (personal edition)
imageUriRequiredStringImage URI, format: registry/namespace/image:tag
registryIdNoStringEnterprise edition image repository ID, required for enterprise edition
imagePortNoNumberContainer listening port, defaults to 9000
entryPointNoStringContainer startup command
commandListNoString[]Startup command list
argsListNoString[]Startup parameters list
containerImageAccelerateNoBooleanwhether to enable image acceleration

Image Type Description:

TypeDescriptionregistryId
personalPersonal Edition Image RepositoryNot required
enterpriseEnterprise 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 Deployment Considerations
  1. Image URI Format: must include a tag (tag), such as :latest or :v1.0.0
  2. Port Configuration: Listens on the 9000 port by default, can be customized via imagePort
  3. Enterprise Edition Image: must specify registryId, otherwise the deployment will fail
  4. Code Download Limitation: Functions deployed via images cannot use tcb fn code download to download code.
  5. scf_bootstrap Skip: The scf_bootstrap check 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:

ParameterDescriptionRequired
fnModule name, specify the SCF configuration to operate onYes
[name...]SCF function name(s). Supports specifying one or more function names.No
--allPull configurations of all functions in the configuration fileNo
-e, --env-id <envId>Environment IdNo
-o, --output <output>Output file path, defaults to cloudbaserc.json in the current directoryNo
--stdoutOutput to console instead of fileNo
--code-secret <codeSecret>CodeSecret for code-encrypted functionsNo
--dir <dir>Specifies the directory for inferring the configuration (when the SCF does not exist)No
--yesSkip interactive confirmation and automatically overwrite existing filesNo

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

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

ParameterDescriptionRequired
fnModule name, specify the SCF configuration to operate onYes
<functionName>SCF function nameNo
--allUpdate configurations for all functions in the configuration fileNo
-e, --env-id <envId>environment IdNo
--timeout <timeout>Function timeout period (in seconds), range: 1-900No
--memory <memory>Function memory size (MB), range: 64-3072No
--env <key=value>Set environment variables, can be used multiple timesNo
--env-mode <mode>Environment variable update mode: merge (merge) or overwrite (overwrite)No
--yesSkip interactive confirmation and directly executeNo

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
Important
  • 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 --yes parameter 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

ParameterDescriptionRequired
fnModule name, specify the SCF configuration to operate onYes
<functionName>SCF function nameNo
--allCompare configurations of all functions in the configuration fileNo
-e, --env-id <envId>Environment IdNo

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
Use Cases
  • 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"
}
]
}
Configuration Instructions
  • The jsonc format supports comments; in actual use, comments need to be removed or the standard JSON format should be used.
  • For HTTP functions, set type to HTTP
  • 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.