Skip to main content

Local Run

Use the local run command to run and debug SCF functions in the development environment, without needing to deploy them to the cloud.

tip

tcb fn run currently only supports the Node.js runtime. If you need to run function-type CloudRun services locally, see CloudRun Local Run.

Basic Usage

tcb fn run [options]

tcb fn run supports two ways of invocation:

  • Run by path (--path): Specify the function directory directly to run with default configuration. No cloudbaserc.json configuration file is required.
  • Run by name (--name): Read the configuration of the corresponding function (handler, envVariables, params, etc.) from the current project's cloudbaserc.json.

Command Parameters

ParameterDescriptionRequired
--path <path>Path to the SCF function, invoked directly with default configuration, no config file requiredOne of --path / --name
--name <name>Function name, reads the corresponding function configuration from cloudbaserc.json for invocationOne of --path / --name
--params <params>Parameters passed to the function, in JSON string formatNo
--debugStart in debug mode (Node Inspector)No
--port <port>Listening port in debug mode, defaults to 9229No
-h, --helpView command help informationNo

Usage Examples

Run by Path

Specify the function directory, which must contain index.js and export a main method:

# Run the function under ./functions/app with default configuration
tcb fn run --path ./functions/app

Run by Name

The project root must contain cloudbaserc.json with the corresponding function configured under functions:

tcb fn run --name app

The function will run based on handler, envVariables, params, etc. configured in cloudbaserc.json. See Function Configuration for details.

Passing Invocation Parameters

Parameters must be a valid JSON string:

tcb fn run --name app --params '{"userId": "123", "action": "query"}'

If params is also set in the function configuration in cloudbaserc.json, the --params passed on the command line takes higher precedence.

Start Debug Mode

With --debug enabled, the process starts in Node Inspector mode and can be connected to using debuggers such as Chrome DevTools or VS Code for breakpoint debugging:

# Use the default port 9229
tcb fn run --path ./functions/app --debug

# Specify a custom debug port
tcb fn run --path ./functions/app --debug --port 9230

Notes

  • Node.js runtime only: Other languages (Python, Java, Go, PHP, etc.) are not supported by tcb fn run for local execution.
  • Function entry conventions:
    • When using --path, the directory must contain index.js and export a main method;
    • When using --name, the entry file and function name are resolved according to handler (defaults to index.main) configured in cloudbaserc.json.
  • Local temporary credentials: If you are logged into the CLI, TENCENTCLOUD_SECRETID, TENCENTCLOUD_SECRETKEY, and TENCENTCLOUD_SESSIONTOKEN environment variables will be automatically injected at runtime, so the function can directly use the Node SDK to call CloudBase resources. If not logged in, these variables will not be injected and calls to CloudBase resources may fail.