Skip to main content

Cloud Function Plugin

Tencent CloudBase Framework Function Plugin

Tencent CloudBase Framework Function Plugin

Github License Npm version issue PRs Welcome star star

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:

FieldRequiredTypeDescription
nameRequiredStringCloud function name, which is the name after the function is deployed
triggersNoArrayTrigger configuration
handlerNoStringFunction handler name. The name format supports the form "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, Go1
memorySizeNoNumberFunction memory, default 256, optional values: 128, 256, 512, 1024, 2048
installDependencyNoBooleanWhether to install dependencies in the cloud, currently only supported for Node.js
functionDistPathNoStringFunction 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.
aclRuleNoRecord<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
codeSecretNoStringSupported 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.
publicNetNoStringSupported 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']
eipNoStringSupported 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

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

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