tcb fn run
Run and debug cloud functions locally without deploying them.
Node.js only
tcb fn run currently supports only the Node.js runtime. To run function-type CloudRun services locally, see CloudRun local run.
Usage
tcb fn run [options]
Two ways to locate a function:
--path: point to the function directory and run with default configuration. Nocloudbaserc.jsonrequired.--name: read the matching function configuration fromcloudbaserc.json(handler,envVariables,params) and run it.
Flags
| Flag | Required | Description | Default |
|---|---|---|---|
--path <path> | One of --path or --name | Function directory, run with default configuration | — |
--name <name> | One of --path or --name | Function name, configuration read from cloudbaserc.json | — |
--params <params> | No | Invocation parameters as a JSON string | — |
--debug | No | Start in Node Inspector mode | — |
--port <port> | No | Debug listen port | 9229 |
Examples
Run by path
The directory must contain index.js exporting a main method.
# Run ./functions/app with default configuration
tcb fn run --path ./functions/app
Run by name
The project directory must contain cloudbaserc.json with the function declared in functions.
tcb fn run --name app
The function runs with handler, envVariables, and params from the configuration file. See Function Configuration.
Pass parameters
tcb fn run --name app --params '{"userId": "123", "action": "query"}'
When both the configuration file and the command line set params, the command line wins.
Start debug mode
# Use the default port 9229
tcb fn run --path ./functions/app --debug
# Use a custom debug port
tcb fn run --path ./functions/app --debug --port 9230
Connect Chrome DevTools or VS Code to the port to set breakpoints.
Notes
- Only Node.js is supported. Python, Java, Go, PHP, and other runtimes cannot run locally through
tcb fn run. - With
--path, the directory must containindex.jsexporting amainmethod. - With
--name, the entry file and function name are resolved fromhandlerincloudbaserc.json, which defaults toindex.main. - When logged in, the runtime injects
TENCENTCLOUD_SECRETID,TENCENTCLOUD_SECRETKEY, andTENCENTCLOUD_SESSIONTOKEN, so the function can call CloudBase resources directly. Without login these variables are absent and such calls may fail.