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",
"functions": [
{
"name": "app",
"timeout": 5,
"runtime": "Nodejs18.15",
"installDependency": true,
"handler": "index.main"
}
]
}
Configuration Items Details
Basic Configuration
| Configuration | Required | Type | Default | Description |
|---|---|---|---|---|
name | Yes | String | - | Cloud function name, the identifier after function deployment |
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-60 |
memorySize | No | Number | 256 | Function memory size (MB), options: 128, 256, 512, 1024, 2048 |
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.9Python3.7Python3.6Python2.7Golang1Java8
- 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"
}
}
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:
{
"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.