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",
"functions": [
{
"name": "app",
"timeout": 5,
"runtime": "Nodejs18.15",
"installDependency": true,
"handler": "index.main"
}
]
}

Configuration Items Details

Basic Configuration

ConfigurationRequiredTypeDefaultDescription
nameYesString-Cloud function name, the identifier after function deployment
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-60
memorySizeNoNumber256Function memory size (MB), options: 128, 256, 512, 1024, 2048

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.9
  • Python3.7
  • Python3.6
  • Python2.7
  • Golang1
  • 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"
}
}

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:

{
"envId": "dev-xxxx",
"functions": [
{
"name": "app",
"handler": "index.main",
"timeout": 5,
"runtime": "Nodejs18.15",
"memorySize": 256,
"installDependency": true,
"envVariables": {
"key": "value",
"DB_HOST": "localhost"
},
"vpc": {
"vpcId": "vpc-xxx",
"subnetId": "subnet-xxx"
},
"triggers": [
{
"name": "myTrigger",
"type": "timer",
"config": "0 0 2 1 * * *"
}
],
"params": {},
"ignore": [
"*.md",
".git",
"node_modules",
"node_modules/**/*",
"test/**/*"
]
}
]
}

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.