Deploying SCF
Using the tcb fn deploy command can quickly deploy SCF to the TCB environment.
tcb fn deploy [options] [name]
Command Parameters
| Parameter | Description | Required |
|---|---|---|
-e, --env-id <envId> | Environment Id | No |
--httpFn | deploy as HTTP SCF | No |
--ws | enable WebSocket protocol when deploying HTTP SCF | No |
--code-secret <codeSecret> | Passing this parameter will protect the code, in the format of 36 uppercase and lowercase letters and numbers | No |
--force | Overwrite the function with the same name if it exists | No |
--path <path> | automatically creates the HTTP service access path | No |
--dir <dir> | specify the folder path of the SCF | No |
--all | deploy all SCF in the configuration file | No |
--deployMode <deployMode> | Deployment mode: cos (recommended by default), zip (not recommended, limited to 1.5 MB), image (container image) | No |
--yes | Skip interactive confirmation and directly execute deployment | No |
--install-dependency <boolean> | Whether to install dependencies in the cloud: true to enable, false to disable (overrides configuration, defaults to following config) | No |
-h, --help | Display command help information | No |
Basic Usage
Method 1: Using a Configuration File (Recommended)
Execute in the project directory containing the cloudbaserc.json configuration file:
# Deploying Specified Functions
tcb fn deploy <functionName>
# Deploying All Functions in the Configuration File
tcb fn deploy --all
# Disable cloud dependency installation, upload local node_modules with the package
tcb fn deploy <functionName> --install-dependency false
# Explicitly enable cloud automatic dependency installation
tcb fn deploy <functionName> --install-dependency true
Method 2: Deploying from the Current Directory
In the function code directory (containing package.json), you can deploy directly without a configuration file:
cd my-function
tcb fn deploy
The CLI automatically reads the function name from package.json and deploys it using the default configuration.
Deploying HTTP Functions
Add the --httpFn parameter to deploy as an HTTP function:
tcb fn deploy <functionName> --httpFn
Usage Example
Standard Workspace Deployment
project/
├── cloudbaserc.json
└── functions/
└── hello/
├── index.js
└── package.json
tcb fn deploy hello
Custom Functions Directory
// cloudbaserc.json
{
"envId": "your-env-id",
"functionRoot": "./functions",
"functions": [
{
"name": "api",
"dir": "./src/cloud-functions/api",
"runtime": "Nodejs20.19"
}
]
}
tcb fn deploy api
Specifying Directories via Command Line
tcb fn deploy hello --dir ./my-custom-path/hello
Deployment Path Parsing
During deployment, the CLI parses the function code path in the following order of priority:
1. --dir parameter (specified via command line) → Highest priority
2. functions[].dir (configuration file) → Secondary priority
3. functionRoot + function name → Default path (functionRoot defaults to ./functions)
4. Current working directory → Fallback when no configuration file is present
| Scenario | Configuration File | --dir | functions.dir | Resolved Path |
|---|---|---|---|---|
| Standard Deployment | ✅ Exists | ❌ | ❌ | functionRoot/function name |
| Custom Directory | ✅ Exists | ❌ | ✅ Specified | functions.dir path |
| Command Line Override | ✅ Exists | ✅ Specified | - | --dir path |
| No Configuration File | ❌ | ❌ | - | Current working directory |
During batch deployment (using --all or not specifying a function name), the --dir parameter is invalid and will be ignored.
Advanced Options
Code Encryption
By using the --code-secret parameter to encrypt the code, the key must be composed of 36 uppercase and lowercase letters and numbers:
tcb fn deploy app --code-secret 7sGLwMnhgEfKmkqg2dMjB6xWk2hCxsAgGR6w
After enabling code encryption, you will not be able to view the code and information of SCF in the Mini Program IDE or Tencent Cloud console.
Overwrite the function with the same name
If a function with the same name already exists in the cloud, the CLI will prompt whether to overwrite it. To force overwrite, you can use the --force parameter:
tcb fn deploy app --force
When using the --force parameter to overwrite a function, both the function's configuration and triggers will be overwritten.