Cloud Function Plugin
Tencent CloudBase Framework Function Plugin
CloudBase Framework "Function" Plugin: Deploy cloud functions from the project to the CloudBase environment with one click via the CloudBase Framework, delivering a production-ready, high-performance, event-driven function computing service with automatic elastic scaling. It integrates with other plugins such as the Website plugin and Node plugin to enable cloud-native integrated development.
Features
- Cost Savings: Achieves significant resource cost reduction through resource scaling, elastic scaling, and flexible billing.
- Minimal Configuration: Automatic framework detection, zero configuration required.
- Language Support:
Node.JS
PHP
Java
Usage
Step 1. Preparations
Specific steps please refer to Preparing the Cloud Development Environment and CloudBase CLI Command Tool
Step 2. Enter the project directory and initialize
If there is an existing function application project
cloudbase
If you want to start a new project from scratch, you can directly execute init to begin a project from a template.
cloudbase init
Step 3. One-Click Deployment
cloudbase framework deploy
Configuration
By default, no configuration is required for use. The following configuration parameters are intended for scenarios with specific requirements.
Configuration Example
After running
cloudbase init, the Cloud Development configuration file
cloudbaserc.json` will be created. You can modify and write plugin configurations in the plugins section of the configuration file.
{
"envId": "{{envId}}",
"framework": {
"plugins": {
"function": {
"use": "@cloudbase/framework-plugin-function",
"inputs": {
"functionRootPath": "./cloudfunctions",
"publishIncludeList": "{{env.publishIncludeList}}",
"functionDefaultConfig": {
"timeout": 5,
"envVariables": {
"FOO": "bar"
},
"runtime": "Nodejs10.15",
"memorySize": 128
},
"functions": [
{
"name": "helloworld",
"envVariables": {
"ABC": "xyz"
}
}
],
"servicePaths": {
"helloworld": "/helloworld"
}
}
}
}
}
}
Configuration Parameters Description
functionRootPath
Functions Root Directory
functionDefaultConfig
Cloud function default configuration has the same configuration format as a single function.
CloudBaseFramework 1.6.1 and later supports this. The configuration of a single function will be merged based on the default configuration.
functions
Function configuration array. The configuration format requirements for each function are as follows:
Field | Required | Type | Description |
---|---|---|---|
name | Required | String | Cloud function name, which is the name after the function is deployed |
triggers | No | Array | Trigger configuration |
handler | No | String | Function handler name. The name format supports the form "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, Go1 |
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 |
functionDistPath | No | String | Function artifact path, relative to the function root directory functionRootPath. For example, for Go, you can specify the binary file path; for Java, you can specify the jar file address. |
aclRule | No | Record<string, any> | Supported since version 1.3, security rule configuration, for example { invoke: true } . Refer to https://docs.cloudbase.net/cloud-function/security-rules.html |
codeSecret | No | String | Supported since version 1.4.0. Code protection secret key. When provided, protects the code by making plaintext code invisible in console/IDE. Format: 36 uppercase/lowercase letters and numbers. |
publicNet | No | String | Supported since version 1.6.14. Specifies whether public network access is enabled in cloud functions. Enabled by default. When a VPC is configured for the cloud function, public network access is disabled by default. Valid values: ['ENABLE','DISABLE'] |
eip | No | String | Supported since version 1.6.14. Whether to enable EIP (fixed public ip) capability. Not available in free environments. Valid values: ['ENABLE','DISABLE'] |
Note: runtime
defaults to Nodejs10.15
. It can be omitted when using Node runtime, but must be specified for Php or Java.
#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 |
servicePaths
Service path configuration
Example:
{
"hello-world": "/helloworld"
}
bumpVersion
Optional. Whether to automatically create a new version.
Selecting the option to automatically create a new version allows for gradual traffic rollout and control in the console; if not selected, in-place updates will be performed automatically.
publishIncludeList
Supported from version 1.6.16. If specified, only the functions in the list will be deployed.
String format, e.g. 'fn1,fn2'
More Plugins
Please visit the CloudBase Framework Plugin List to use other plugins in combination
Documentation Resources
- CloudBase official website: https://tcb.cloud.tencent.com/
- CloudBase Static Website Setup Guide: https://docs.cloudbase.net/hosting/
- CloudBase Console: https://console.cloud.tencent.com/tcb