sls init http-demo
. http-demo├── serverless.yml # 配置文件├── package.json # 依赖项文件├── scf_bootstrap # 项目启动文件└── index.js # 服务函数
serverless.yml,查看配置信息。
您只需要在 yml 里新增 type 参数,指定函数类型,即可完成 Web 类型函数部署。type 参数时,默认为事件型函数。scf_bootstrap 启动文件,您可以在 yml 里指定 entryFile 参数指定入口函数,组件会根据运行语言,为您生成默认 scf_bootstrap 启动文件完成部署。部署完成后,需根据您的实际项目情况,在 云函数控制台 修改 scf_bootstrap 文件内容。yml 如下:component: scfname: httpinputs:src:src: ./exclude:- .env# 指定 SCF 类型为 Web 类型type: webname: web-functionregion: ap-guangzhouruntime: Nodejs12.16# 对于 Node.js,可以支持打开自动安装依赖installDependency: trueevents:- apigw:parameters:protocols:- http- httpsenvironment: releaseendpoints:- path: /method: ANY
sls deploy 命令,即可完成服务部署。示例如下:$ scf deployserverless-cloud-frameworkAction: "deploy" - Stage: "dev" - App: "http" - Name: "http"type: webfunctionName: web-functiondescription: This is a function in http applicationnamespace: defaultruntime: Nodejs12.16handler:memorySize: 128lastVersion: $LATESTtraffic: 1triggers:-NeedCreate: truecreated: trueserviceId: service-xxxxxxserviceName: serverlesssubDomain: service-xxxxxx.cd.apigw.tencentcs.comprotocols: http&httpsenvironment: releaseapiList:-path: /method: ANYapiName: indexcreated: trueauthType: NONEbusinessType: NORMALisBase64Encoded: falseapiId: api-xxxxxxinternalDomain:url: https://service-xxxx.cd.apigw.tencentcs.com/release/18s › http › 执行成功
$ scf logserverless-cloud-frameworkAction: "log" - Stage: "dev" - App: "http" - Name: "http"-requestId: xxxxxretryNum: 0startTime: 1624262955432memoryUsage: 0.00duration: 0message:"""-requestId: xxxxxretryNum: 0startTime: 1624262955432memoryUsage: 0.00duration: 0message:"""

curl https://service-xxx.cd.apigw.tencentcs.com/release/
sls remove
文档反馈