The development mode enables you to write code for and develop and debug projects in development status more easily, so that you can continuously focus on the process from development to debugging while minimizing the interruptions caused by other tasks such as packaging and update.
Under a project, you can run serverless dev
to enter the development mode:
Below is an example:
$ sls dev
serverless ⚡ framework
Dev Mode - Watching your Component for changes and enabling streaming logs, if supported...
Debugging listening on ws://127.0.0.1:9222.
For help see https://nodejs.org/en/docs/inspector.
Please open chorme, and visit chrome://inspect, click [Open dedicated DevTools for Node] to debug your code.
--------------------- The realtime log ---------------------
17:13:38 - express-api-demo - deployment
region: ap-guangzhou
apigw:
serviceId: service-b77xtibo
subDomain: service-b77xtibo-1253970226.gz.apigw.tencentcs.com
environment: release
url: http://service-b77xtibo-1253970226.gz.apigw.tencentcs.com/release/
scf:
functionName: express_component_6r6xkh60k
runtime: Nodejs10.15
namespace: default
express-api-demo › Watching
After you enter the development mode, the Serverless tool will output the deployed content and start continuous file monitoring. When a code file is modified, it will be automatically deployed again to sync the local file to the cloud.
Deploy again and output the deployment information:
express-api-demo › Deploying ...
Debugging listening on ws://127.0.0.1:9222.
For help see https://nodejs.org/en/docs/inspector.
Please open chorme, and visit chrome://inspect, click [Open dedicated DevTools for Node] to debug your code.
--------------------- The realtime log ---------------------
21:11:31 - express-api-demo - deployment
region: ap-guangzhou
apigw:
serviceId: service-b7dlqkyy
subDomain: service-b7dlqkyy-1253970226.gz.apigw.tencentcs.com
environment: release
url: http://service-b7dlqkyy-1253970226.gz.apigw.tencentcs.com/release/
scf:
functionName: express_component_uo5v2vp
runtime: Nodejs10.15
namespace: default
Note:Currently,
serverless dev
supports only by the Node.js 10 runtime environment. It will support real-time logging in more environments such as Python and PHP.
You can press Ctrl+C to exit the development mode (dev
mode).
express-api-demo › Disabling Dev Mode & Closing ...
express-api-demo › Dev Mode Closed
For projects whose runtime environment is Node.js 10+, you can connect them to in-cloud debugging by enabling in-cloud debugging and using a debugging tool such as Chrome DevTools or VS Code Debugger.
When you enter the development mode as instructed above, if the project is a function whose runtime environment is Node.js 10 or above, in-cloud debugging will be automatically enabled and debugging information will be output.
For example, when you enable the development mode, if the following information is output, in-cloud debugging has been enabled for this function.
Debugging listening on ws://127.0.0.1:9222.
For help see https://nodejs.org/en/docs/inspector.
Please open chorme, and visit chrome://inspect, click [Open dedicated DevTools for Node] to debug your code.
The following steps are used as an example to describe how to use DevTools in Chrome to connect to a remote environment for debugging:
chrome://inspect/
in the address bar to access it.localhost:9229
or localhost:9222
exists in "Configure" under "Devices", which corresponds to the output after in-cloud debugging is enabled./var/user/
directory.When you exit the development mode, in-cloud debugging will be disabled automatically.
The Serverless Framework SCF component supports triggering functions with the invoke
command for debugging. For a function successfully deployed by running sls deploy
, enter the project directory and run the following command to invoke it:
sls invoke --inputs function=functionName clientContext='{"weights":{"2":0.1}}'
Note:
- The
invoke
command must be executed in the same directory as theserverless.yml
file deployed for the function.clientContext
is the JSON string passed when the function is triggered. You can simulate different triggering events according to the JSON string format in the triggering event template.
Was this page helpful?