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.
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. Nocloudbaserc.jsonconfiguration file is required. - Run by name (
--name): Read the configuration of the corresponding function (handler,envVariables,params, etc.) from the current project'scloudbaserc.json.
Command Parameters
| Parameter | Description | Required |
|---|---|---|
--path <path> | Path to the SCF function, invoked directly with default configuration, no config file required | One of --path / --name |
--name <name> | Function name, reads the corresponding function configuration from cloudbaserc.json for invocation | One of --path / --name |
--params <params> | Parameters passed to the function, in JSON string format | No |
--debug | Start in debug mode (Node Inspector) | No |
--port <port> | Listening port in debug mode, defaults to 9229 | No |
-h, --help | View command help information | No |
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 runfor local execution. - Function entry conventions:
- When using
--path, the directory must containindex.jsand export amainmethod; - When using
--name, the entry file and function name are resolved according tohandler(defaults toindex.main) configured incloudbaserc.json.
- When using
- Local temporary credentials: If you are logged into the CLI,
TENCENTCLOUD_SECRETID,TENCENTCLOUD_SECRETKEY, andTENCENTCLOUD_SESSIONTOKENenvironment 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.