Deployment
The total file size for deploying functions using the
fn deploy` command must not exceed 50 M; otherwise, deployment may fail.
In a project containing a cloudbaserc.json
configuration file, you can directly use the following command to deploy cloud functions:
tcb fn deploy <functionName>
When using fn deploy
, the functionName
option can be omitted. If functionName
is omitted, Cloudbase CLI will deploy all functions in the configuration file.
# Deploy All Functions in the Configuration File
tcb fn deploy
All Parameters
Usage: tcb fn deploy [options] [name]
Deploy cloud function
Options:
-e, --envId <envId> Environment Id
--code-secret <codeSecret> Passing this parameter will protect the code. The format should be 36 characters consisting of uppercase letters, lowercase letters, and numbers.
--force Overwrites the function if a function with the same name exists.
--path <path> Automatically creates the access path for the HTTP access service.
--all Deploy all cloud functions contained in the configuration file.
--dir <dir> Specify the folder path for the cloud function
-h, --help Display command help information
Code Encryption
When deploying cloud functions, you can encrypt the uploaded code by specifying --code-secret codeSecret
. codeSecret
must be 36 characters and consist of uppercase letters, lowercase letters, and numbers:
tcb fn deploy app --code-secret 7sGLwMnhgEfKmkqg2dMjB6xWk2hCxsAgGR6w
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.
Overwriting Functions with the Same Name
When deploying a function, you may encounter a situation where a cloud function with the same name already exists. In this case, Cloudbase CLI will abort the deployment and ask whether to overwrite the function with the same name. You can choose to overwrite the existing cloud function or terminate the deployment.
If you are sure to overwrite the cloud function with the same name that may exist, you can append the --force
option after the command to instruct Cloudbase CLI to overwrite the existing cloud function.
tcb fn deploy dev --force
Note: When overwriting a function, both its configuration and triggers will also be overwritten.
Default Option
Cloudbase CLI provides default options for Node.js cloud functions, so you do not need to specify configurations when deploying Node.js cloud functions and can deploy using the default configuration.
Cloud Function Default Configuration:
{
// Timeout 5S
"timeout": 5,
// Runtime
"runtime": "Nodejs10.15",
// Auto-install dependencies
"installDependency": true,
// Handler Entry
"handler": "index.main",
// Ignore the node_modules directory
"ignore": ["node_modules", "node_modules/**/*", ".git"]
}
What the deploy Command Does
The
fn deploycommand reads the configuration of the specified function in the
cloudbaserc.json` file and performs the following tasks:
- Package the function into a compressed file and upload the function code.
- Deploy function configurations, including timeout settings and network configurations.
- Deploy the function trigger.