Skip to main content

Deploy Cloud Functions

Use the tcb fn deploy command to deploy cloud functions to CloudBase environment.

Basic Usage

# Deploy specified cloud function
tcb fn deploy <functionName>

# Deploy all cloud functions in config file
tcb fn deploy

Command Parameters

ParameterDescriptionRequired
-e, --envId <envId>Environment IDNo
--code-secret <codeSecret>Code encryption key, 36 characters of uppercase/lowercase letters and numbersNo
--forceOverwrite function if same name existsNo
--path <path>Automatically create HTTP access service pathNo
--allDeploy all cloud functions in config fileNo
--dir <dir>Specify cloud function folder pathNo

Usage Examples

# Deploy app function
tcb fn deploy app

# Deploy all functions
tcb fn deploy

# Deploy with code encryption
tcb fn deploy app --code-secret 7sGLwMnhgEfKmkqg2dMjB6xWk2hCxsAgGR6w

# Force overwrite function with same name
tcb fn deploy app --force

# Deploy with specified function directory
tcb fn deploy app --dir ./functions/app

Deployment Process

When executing the tcb fn deploy command, CLI automatically completes the following operations:

  1. Package and Upload: Package function code as a compressed file and upload
  2. Configuration Update: Update function configuration (timeout, memory, environment variables, network configuration, etc.)
  3. Trigger Deployment: Deploy or update triggers according to config file

Default Configuration

For Node.js cloud functions, CLI provides default configuration, deployment possible without manual configuration:

{
"timeout": 5,
"runtime": "Nodejs10.15",
"installDependency": true,
"handler": "index.main",
"ignore": ["node_modules", "node_modules/**/*", ".git"]
}

Important Notes

  • Total function file size cannot exceed 50 MB
  • After enabling code encryption, function code and information cannot be viewed in Mini Program IDE or Tencent Cloud Console
  • Using --force parameter to overwrite will also overwrite function configuration and triggers
  • Environment variable configuration in cloudbaserc.json will completely overwrite online configured environment variables during deployment