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.

This article only describes the functions configuration fields; for deployment steps, see Deploy SCF, and for pulling, updating, and comparing configurations, see Configuration Operations.

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.

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 GroupFields
Basic Configuration ItemsfunctionRoot, name, type, dir, handler, runtime, timeout, memorySize, protocolType, protocolParams, instanceConcurrencyConfig, imageConfig, buildStrategy
Code and Dependency Configurationignore, installDependency, codeSecret
Advanced ConfigurationenvVariables, vpc, triggers, params, role, clsLogsetId, clsTopicId, public, gatewayPath
Runtime EnvironmentList of supported runtime versions
Trigger Configurationname, type, config
VPC ConfigurationvpcId, subnetId
WebSocket ConfigurationwsParams.idleTimeOut
Concurrency ConfigurationmaxConcurrency, dynamicEnabled
Image ConfigurationimageType, 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 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
runtimeNoStringNodejs20.19Runtime 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
buildStrategyNoStringzipHTTP 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 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. The update behavior during deployment depends on the CLI version. See Environment Variable Update Rules
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
publicNoBooleanfalseWhether to allow anonymous access (HTTP functions only). When true, anonymous access is automatically enabled after deployment (OPA Rego), allowing invocation via URL without login
gatewayPathNoString-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.15
  • Nodejs16.13

Other Language Runtimes

  • Php8.0
  • Php7.4
  • Python3.11
  • Python3.10
  • Python3.9
  • Python3.7
  • Go1
  • Java11

For complete runtime environment information, see Runtime Environment Support.

Runtime Notes
  • Node.js projects use the Nodejs20.19 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 * * *"
}
]
}
Trigger Limitations

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.

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"
}
]
}
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
  • 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.

Important

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)