Skip to main content

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:

ParameterDescriptionDefault Value
-l, --limit <limit>Returned data length20
-o, --offset <offset>Data offset0

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:

ParameterDescriptionRequired
functionNameFunction nameYes
destPathDownload destination pathNo
--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-version or with $LATEST, the latest function code is downloaded (same behavior as before)
  • --fn-version only supports $LATEST or 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-versions to check published versions

Update Function Code​

tcb fn code update <functionName> [options]

Command Parameters:

ParameterDescriptionRequired
functionNameFunction nameYes
-e, --env-id <envId>Environment IdNo
--deployMode <deployMode>Deployment mode: cos (default), zip (limited to 1.5 MB)No
--yesSkip interactive confirmationNo

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:

ParameterDescriptionRequired
functionNameFunction NameNo (If not specified, all functions in the configuration file will be deleted)
-e, --env-id <envId>Environment IDNo
--forceForce deletion and skip confirmation promptsNo
--dry-runSimulate the operation to preview functions to be deleted without actual executionNo

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:

ParameterDescriptionRequired
functionNameFunction nameYes
descriptionVersion descriptionNo

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:

ParameterDescriptionRequired
nameFunction nameYes
--output-file <file>Output file path, e.g., .env.localYes
-e, --env-id <envId>Environment ID; selected interactively when omittedNo

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 destPath is not specified, the code will be downloaded to the directory configured by functionRoot.
  • After downloading, a folder named after the function will be automatically created.
  • When downloading a non-$LATEST version 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 update only updates the function code and execution entry point, which is faster
  • tcb fn deploy updates 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 --force parameter 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 download to 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 $LATEST version (the latest version) by default
  • Only the $LATEST version's configuration and code can be modified
  • When publishing a new version, an immutable snapshot is created based on the current $LATEST version
  • Published version numbers increment sequentially (1, 2, 3...), and their content cannot be modified

Pull Function Environment Variables:

  • --output-file is required; an error is reported when it is omitted
  • The exported file uses the KEY=value format, 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