SCF Management
Using SCF management commands, you can view, invoke, copy, and delete SCF functions, and manage function versions.
View Function List
tcb fn list
Command Parameters:
| Parameter | Description | Default Value |
|---|---|---|
-l, --limit <limit> | Returned data length | 20 |
-o, --offset <offset> | Data offset | 0 |
Usage Example:
# List All Functions
tcb fn list
# List the First 10 Functions
tcb fn list -l 10
# List Functions 21-40
tcb fn list -l 20 -o 20
View Function Details
tcb fn detail <functionName>
Usage Example:
# View app Function Details
tcb fn detail app
Download Function Code
tcb fn code download <functionName> [destPath] [options]
Parameter Description:
| Parameter | Description | Required |
|---|---|---|
functionName | Function name | Yes |
destPath | Download destination path | No |
--fn-version <version> | Function version number, defaults to $LATEST; supports published positive integer versions (e.g., 1) | No |
Usage Example:
# Download to the default directory ($LATEST version)
tcb fn code download app
# Download to the specified directory
tcb fn code download app ./my-functions/app
# Download a specific version (e.g., version 1) to the specified directory
tcb fn code download app ./my-functions/app-v1 --fn-version 1
# Download a specific version; when no path is specified, code is saved to <functionRoot>/<functionName>-v<version>/ automatically
tcb fn code download app --fn-version 1
# When explicitly downloading the $LATEST version, wrap it in single quotes to prevent the shell from expanding $LATEST as a variable
tcb fn code download app --fn-version '$LATEST'
Version Notes:
- Without
--fn-versionor with$LATEST, the latest function code is downloaded (same behavior as before) --fn-versiononly supports$LATESTor published positive integer version numbers (e.g.,1,2); invalid versions will cause an immediate error- When downloading a specific version without
destPath, the code is saved to the<functionRoot>/<functionName>-v<version>/directory to avoid overwriting the default directory - If the version does not exist, the available version list of the function will be shown; use
tcb fn list-function-versionsto check published versions
Update Function Code
tcb fn code update <functionName> [options]
Command Parameters:
| Parameter | Description | Required |
|---|---|---|
functionName | Function name | Yes |
-e, --env-id <envId> | Environment Id | No |
--deployMode <deployMode> | Deployment mode: cos (default), zip (limited to 1.5 MB) | No |
--yes | Skip interactive confirmation | No |
Usage Example:
# Update app Function Code
tcb fn code update app
# Update Code Using zip Mode
tcb fn code update app --deployMode zip
# Skip Confirmation and Update Directly
tcb fn code update app --yes
Invoke SCF
# Invoke Specified Function
tcb fn invoke <functionName>
# Invoke All Functions in Configuration File
tcb fn invoke
Parameters Passed:
# Linux / macOS
tcb fn invoke app --params '{"key1": "value1", "key2": "value2"}'
# Windows (Double Quotes Need Escaping)
tcb fn invoke app --params "{\"key1\": \"value1\", \"key2\": \"value2\"}"
Usage Example:
# Invoke app Function Without Parameters
tcb fn invoke app
# Invoke Function and Pass Parameters
tcb fn invoke app --params '{"userId": "123", "action": "query"}'
# Invoke All Functions
tcb fn invoke
Copying SCF
tcb fn copy <sourceName> <targetName>
Usage Example:
# Copy app Function to app2
tcb fn copy app app2
# Force overwrite existing target functions
tcb fn copy app app2 --force
Deleting SCF
# Delete Specified Function
tcb fn delete <functionName>
# Delete All Functions in Configuration File
tcb fn delete
Command Parameters:
| Parameter | Description | Required |
|---|---|---|
functionName | Function Name | No (If not specified, all functions in the configuration file will be deleted) |
-e, --env-id <envId> | Environment ID | No |
--force | Force deletion and skip confirmation prompts | No |
--dry-run | Simulate the operation to preview functions to be deleted without actual execution | No |
Usage Example:
# Deleting app Function
tcb fn delete app
# Delete All Functions
tcb fn delete
# Preview functions to be deleted (without actual execution)
tcb fn delete app --dry-run
# Force Delete, Skip Confirmation
tcb fn delete app --force
Version Management
Release a New Version
tcb fn publish-version <functionName> [description]
Parameter Description:
| Parameter | Description | Required |
|---|---|---|
functionName | Function name | Yes |
description | Version description | No |
Usage Example:
# Release a New Version (without description)
tcb fn publish-version app
# Release a New Version and Add Description
tcb fn publish-version app "Fixed login logic issues"
# Release a Version with Feature Updates
tcb fn publish-version app "v1.2.0: added new user profile feature"
View Version List
tcb fn list-function-versions <functionName>
Usage Example:
# View All Versions of the app Function
tcb fn list-function-versions app
Pull Function Environment Variables
Use the tcb fn env pull command to pull a function's environment variables to a local file:
tcb fn env pull <name> --output-file <file> [options]
Parameter Description:
| Parameter | Description | Required |
|---|---|---|
name | Function name | Yes |
--output-file <file> | Output file path, e.g., .env.local | Yes |
-e, --env-id <envId> | Environment ID; selected interactively when omitted | No |
Usage Example:
# Export the app function's environment variables to .env
tcb fn env pull app --output-file .env
# Export to .env.local and specify an environment
tcb fn env pull app --output-file .env.local --env-id env-xxxx
# Export to a directory and output the result as JSON
tcb fn env pull app --output-file ./configs/dev.env --json
Precautions
Download Function Code:
- If
destPathis not specified, the code will be downloaded to the directory configured byfunctionRoot. - After downloading, a folder named after the function will be automatically created.
- When downloading a non-
$LATESTversion with--fn-version, a<functionName>-v<version>folder is created to distinguish it from the default directory and avoid overwriting. - The version number semantics align with
tcb fn publish-version/tcb fn list-function-versions.
Difference Between code update and deploy:
tcb fn code updateonly updates the function code and execution entry point, which is fastertcb fn deployupdates code, configuration, and triggers, providing a more complete feature set.
Copying SCF:
- Function code, configuration (timeout, memory, environment variables, VPC, etc.), execution entry point, and runtime will be copied
- Triggers of the function will not be copied and need to be manually configured
- If the target function name already exists, the
--forceparameter must be used to force overwrite
Deleting SCF:
- The deletion operation is irreversible; please proceed with caution.
- Before deletion, it is recommended to use
tcb fn code downloadto back up the function code - After deleting the function, related triggers, logs, etc. will also be cleaned up
Version Management:
- After a function is created, it has a
$LATESTversion (the latest version) by default - Only the
$LATESTversion's configuration and code can be modified - When publishing a new version, an immutable snapshot is created based on the current
$LATESTversion - Published version numbers increment sequentially (1, 2, 3...), and their content cannot be modified
Pull Function Environment Variables:
--output-fileis required; an error is reported when it is omitted- The exported file uses the
KEY=valueformat, with newlines and double quotes escaped automatically - With
--json, the output includes the function name, environment ID, output file path, variable count, and variable name list