Configuration
In the CLI configuration file, the functions array can contain multiple function configuration items. Function configuration items include function name (name), function runtime configuration (config), function invocation parameters (params), and other function-related information, which affect the behavior of function operations.
Function Configuration Item
A simple example:
{
// Associate Environment ID
"envId": "dev-xxxx",
// Function Configuration
"functions": [
{
// The name of the function folder under the functions directory, which is the function name
"name": "app",
// Timeout, unit: S
"timeout": 5,
"runtime": "Nodejs10.15",
"installDependency": true,
"handler": "index.main"
}
]
}
Starting from version 0.6.0, to simplify usage, we have flattened the config
option under the functions
option in the cloudbaserc.json
configuration file. All configuration items originally in the config
option can now be written directly under the functions
option.
Below are all currently supported configuration items.
Configuration Item | Required | Type | Description |
---|---|---|---|
name | Required | String | Cloud function name, which is the name after the function is deployed |
params | No | Object/JSONObject | Function input parameters when CIL invokes the cloud function |
triggers | No | Array<CloudFunctionTrigger> | Trigger configuration |
handler | No | String | Function handler name, which supports the format "filename.functionname" |
ignore | No | String/Array<String> | Files to ignore when deploying/updating cloud function code, supporting glob matching patterns |
timeout | No | Number | Function timeout (1 - 60S) |
envVariables | No | Object | Contains key-value pairs of environment variables |
vpc | No | VPC | VPC configuration |
runtime | No | String | Runtime environment configuration. Valid values: Nodejs8.9, Nodejs10.15 Php7, Java8 |
memorySize | No | Number | Function memory, default 256, optional values: 128, 256, 512, 1024, 2048 |
installDependency | No | Boolean | Whether to install dependencies in the cloud, currently only supported for Node.js |
codeSecret | No | String | Code encryption secret key, in the format of 36-digit alphanumeric characters with upper/lowercase letters |
- Note:
runtime
defaults toNodejs10.15
. It can be left blank when using Node.js runtime, but must be specified for Php or Java. - After enabling code encryption, you will not be able to view cloud function code and information in the Mini Program IDE or Tencent Cloud console
CloudFunctionTrigger
Name | Required | Type | Description |
---|---|---|---|
name | Yes | String | Trigger name |
type | Yes | String | Trigger type, optional values: timer |
config | Yes | String | Trigger configuration. For timer triggers, the config should be a cron expression. |
VPC
Name | Required | Type | Description |
---|---|---|---|
vpcId | Required | String | VPC Id |
subnetId | Required | String | VPC subnet Id |
Updating Function Runtime Configuration
When creating a function, Cloudbase CLI provides default configurations, so you can deploy the function directly without adding configuration information. You can also modify the function's runtime configuration using the following command:
# Update app function configuration
tcb fn config update app
# Update configuration information for all functions in the configuration file
tcb fn config update
Currently supported function configurations that can be modified include timeout, envVariables, runtime, vpc network, installDependency, and other options.
CloudBase CLI reads the function configuration information from the configuration file and updates it. CloudBase CLI updates all configurations of the functions present in the configuration file and currently does not support updating individual configuration options.
Configuration Item Reference
{
// Associate Environment ID
"envId": "dev-xxxx",
// Function Configuration
"functions": [
{
// The name of the function folder under the functions directory, which is the function name
"name": "app",
// Timeout, unit: S
"timeout": 5,
// Environment Variables
"envVariables": {
"key": "value"
},
// VPC configuration; if not using a VPC, this can be omitted
"vpc": {
// vpc id
"vpcId": "vpc-xxx",
// Subnet id
"subnetId": "subnet-xxx"
},
// Runtime, currently available options include: Nodejs 18.15, Nodejs 16.13, Nodejs 14.18, Nodejs 12.16, Nodejs 10.15, Php 8.0, Php 7.4, Php 7.2, Python 3.9, Python 3.7, Python 3.6, Python 2.7, Golang 1, Java 8
// This parameter can be omitted and defaults to Nodejs10.15
"runtime": "Nodejs10.15",
// Whether to install dependencies in the cloud, only supported for Node.js projects
"installDependency": true,
// Function trigger, see documentation for details: https://cloud.tencent.com/document/product/876/32314
"triggers": [
{
// name: Trigger name
"name": "myTrigger",
// type: Trigger type. Currently only supports timer (which is a scheduled trigger)
"type": "timer",
// config: Trigger configuration. For timer triggers, the config should be a cron expression.
"config": "0 0 2 1 * * *"
}
],
// Function entry point. For Node.js and PHP projects, this can be omitted and defaults to index.main
// Since the handler configuration for Java is specific, it cannot be omitted when the runtime is Java
// e.g. package.Class::mainHandler
"handler": "index.main",
// fn invoke invocation parameters for local cloud function triggering
"params": {},
// Files to ignore when deploying/updating cloud functions
"ignore": [
// Ignore markdown files
"*.md",
// Ignore the node_modules directory
"node_modules",
"node_modules/**/*"
]
}
]
}