Skip to main content

Quick Start

This guide explains how to quickly develop and deploy cloud functions using CloudBase CLI.

Standard Workspace

Cloud function projects use the following standard directory structure:

project/
├── functions/ # Functions directory (stores all function code)
│ └── <functionName>/ # Specific function directory
│ ├── index.js # Function entry file
│ └── package.json # Dependencies config (optional)
└── cloudbaserc.json # Project configuration file
  • functions/: Root directory for function code, specified by functionRoot in cloudbaserc.json
  • cloudbaserc.json: Project configuration file containing environment ID and function settings
tip

For detailed configuration options, see Configuration - Functions.

Quick Experience

1. Install and Login CLI

npm install -g @cloudbase/cli
tcb login

2. Initialize Configuration

# Pull single function config, generates default config if not exists
tcb config pull fn hello-world

# Pull multiple function configs at once
tcb config pull fn func1 func2 func3

3. Write Function Code

Create a cloud function in functions/hello-world/index.js:

exports.main = async (event, context) => {
return {
message: 'Hello World!',
input: event
};
};

4. Deploy Function

tcb fn deploy hello-world

After successful deployment, you can test the function in CloudBase Console.

Create New Function

tcb config pull fn <functionName>    # 1. Initialize config
# Write code in functions/<functionName>/ directory
tcb fn deploy <functionName> # 2. Deploy function

Update Function

tcb config pull fn <functionName>    # 1. Sync online config
tcb fn code download <functionName> # 2. Download online code (if no local code)
# Modify code in functions/<functionName>/
tcb fn code update <functionName> # 3. Update code

Batch Operations

# Pull multiple function configs
tcb config pull fn func1 func2 func3

# Pull all functions in config file
tcb config pull fn --all

# Auto-confirm mode (skip interactive confirmation)
tcb config pull fn --all --yes

Important Notes

  • Sync config before operations: Run tcb config pull fn before each operation to ensure local config matches online
  • Use config file for deployment: Avoid interactive operations to ensure repeatable and automation-friendly processes
  • Centralized environment variables: Manage environment variables through config files instead of manual modifications

Next Steps