本文介绍如何通过fun local start的相关命令调试函数。
通过VSCode调试本地HTTP触发器函数
下文以Node.js为例,介绍如何通过VSCode调试HTTP函数。
HTTP触发器在本地调试的方法与使用事件触发函数的方法一致,通过-d
或--debug-port
参数指定。同时,还支持通过-c
或—config
参数在调试时显示调试IDE的配置信息。
- 执行以下命令使用调试模式运行函数。
fun local start —debug 3000 —config vscode
输出示例:

说明 在返回结果中您可以看到template.yml文件中声明的函数已经被注册成功。
- 根据服务名、函数名或HTTP触发器名称选择合适的URL,使用浏览器打开目标URL。
浏览器页面将一直无响应,在终端中显示的日志如下。您需要将日志中返回的配置信息复制到VSCode调试器中进行配置。
skip pulling image aliyunfc/runtime-python3.6:1.2.0...
you can paste these config to .vscode/launch.json, and then attach to your running function
///////////////// config begin /////////////////
{
"version": "0.2.0",
"configurations": [
{
"name": "fc/local-http-demo/python3",
"type": "python",
"request": "attach",
"host": "localhost",
"port": 3000,
"pathMappings": [
{
"localRoot": "/Users/tan/fun_local_http_demo/python3",
"remoteRoot": "/code"
}
]
}
]
}
///////////////// config end /////////////////
FunctionCompute python3 runtime inited.
FC Invoke Start RequestId: 04c57fba-cbe9-4c1f-8c57-f8e0b539fa08
- 单击VSCode编辑器侧边栏设置断点,单击
图标,即可完成调试。动态演示过程如下。
