Skip to main content

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"
}
]
}
Note

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 ItemRequiredTypeDescription
nameRequiredStringCloud function name, which is the name after the function is deployed
paramsNoObject/JSONObjectFunction input parameters when CIL invokes the cloud function
triggersNoArray<CloudFunctionTrigger>Trigger configuration
handlerNoStringFunction handler name, which supports the format "filename.functionname"
ignoreNoString/Array<String>Files to ignore when deploying/updating cloud function code, supporting glob matching patterns
timeoutNoNumberFunction timeout (1 - 60S)
envVariablesNoObjectContains key-value pairs of environment variables
vpcNoVPCVPC configuration
runtimeNoStringRuntime environment configuration. Valid values: Nodejs8.9, Nodejs10.15 Php7, Java8
memorySizeNoNumberFunction memory, default 256, optional values: 128, 256, 512, 1024, 2048
installDependencyNoBooleanWhether to install dependencies in the cloud, currently only supported for Node.js
codeSecretNoStringCode encryption secret key, in the format of 36-digit alphanumeric characters with upper/lowercase letters
  • Note: runtime defaults to Nodejs10.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

NameRequiredTypeDescription
nameYesStringTrigger name
typeYesStringTrigger type, optional values: timer
configYesStringTrigger configuration. For timer triggers, the config should be a cron expression.

VPC

NameRequiredTypeDescription
vpcIdRequiredStringVPC Id
subnetIdRequiredStringVPC 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/**/*"
]
}
]
}