HTTP 组件

最近更新时间:2026-05-08 11:32:41

我的收藏

组件概述

腾讯云 SCF 云函数组件通过使用 安装 Serverless Cloud Framework,基于云上 Serverless 服务(云函数及触发器等),支持部署、开发 Web 类型的应用,例如 Express、Koa、Next.js、Vue-starter、React-starter 等。

操作步骤

创建

方式1:参考 快速创建应用模板,选择 SCF 项目模板进行创建。
方式2:直接使用scf init命令创建。例如,快速创建 Node.js 示例:
scf init express-starter

部署

执行cd express-starter进入项目目录,执行scf deploy命令,将会弹出二维码,直接扫码授权进行部署。

查看

执行scf info命令,查看您部署的项目信息。

移除

执行scf remove命令,移除您已经部署的项目。
注意:
使用 remove 命令后,将删除已部署的应用,同时删除对应的函数,且无法恢复,请谨慎使用此命令。

配置详情

全部配置

# serverless.yml
#应用组织信息
app: '' # 应用名称。留空则默认取当前组件的实例名称为app名称。
stage: '' # 环境名称。默认值是 dev。建议使用${env.STAGE}变量定义环境名称
#组件信息
component: http
name: expressDemo
#组件参数配置
inputs:
region: ap-shanghai # 云函数所在区域
src: # 部署src下的文件代码,并打包成zip上传到bucket上
src: ./ # 本地需要打包的文件目录
exclude: # 被排除的文件或目录
- .env
# src: # 在指定存储桶bucket中已经存在了object代码,直接部署
# bucket: bucket01 # bucket name,当前会默认在bucket name后增加 appid 后缀, 本例中为 bucket01-appid
# object: cos.zip # bucket key 指定存储桶内的文件
role: exRole # 云函数执行角色
faas:
runtime: Nodejs22.21 # runtime版本
framework: express
name: ${name} # 云函数名称
memorySize: 512 # 内存大小,单位MB
timeout: 10 # 超时时间,单位秒
initTimeout: 3 # 初始化超时时间,单位秒
publicAccess: true # 是否开启公网访问
eip: true # 是否开启固定IP,true: 开启, false: 不开启,默认不开启
asyncRunEnable: true # 是否启用异步执行(长时间运行)
traceEnable: true # 是否状态追踪
msgTTL: 21600 # 消息保留时间,单位秒
retryNum: 2 # 重试次数
dnsCache: true # 是否开启dns缓存,true: 开启, false: 不开启,默认不开启
overClockConfig: # 请求缓冲队列
timeOut: 15 # 最大缓冲时间,单位秒,范围 1-15秒
instanceConcurrencyConfig: # 单实例多并发配置,仅web函数支持开启
enable: true #是否开启
dynamicEnabled: false #是否开启智能动态并发,true: 动态并发,false:表示静态并发
maxConcurrency: 1 #最大并发数,dynamicEnabled是false时,可进行设置
protocolType: 'WS' #当前支持 WebSockets 协议,值为 WS,只有 type:web 时此配置生效。
protocolParams:
wsParams:
idleTimeOut: 60 #空闲超时时间, 单位秒,默认15s。可配置范围1-1800s
vpc: # 私有网络配置
vpcId: vpc-3lw0tiry # 私有网络的Id
subnetId: subnet-7na554xj # 子网ID
cfs: # cfs配置
- cfsId: cfs-cj362tcj # cfs ID
mountInsId: cfs-cj362tcj # mout ID
localMountDir: /mnt/ # 本地挂载路径
remoteMountDir: / # 远程挂载路径
# layers:
# - name: layerName # layer名称
# version: 1 # 版本
cls: # 函数日志
logsetId: 3010c83a-f46d-45a8-94ba-d1567e8ca2f2
topicId: 9bedc538-3f03-4cc4-9eb3-376533d6db12
environments: # 环境变量
- key: envKey
value: envValue
tags:
- key: tagKey
value: tagValue
image: # 镜像配置
registryId: tcr-xxx # 容器镜像服务名称,企业版必须
imageType: personal # 镜像类型:personal - 个人,enterprise - 企业版,public - 镜像模板
imageUrl: ccr.ccs.tencentyun.com/sls-scf/nodejs_test:latest@sha256:xxx
command: node index.js # 容器启动命令
args: test # 容器启动参数
containerImageAccelerate: true # 是否开启镜像加速
imagePort: 9000 # -1表示 job镜像, 9000 表示webServer镜像。不传或为空时,默认取9000
events: # 触发器
- http: # 函数URL
parameters:
netConfig:
enableIntranet: true
enableExtranet: true
qualifier: $DEFAULT
authType: NONE

配置描述

各项配置的具体描述,请参见 云函数 SCF 组件配置描述,以确保格式保持一致。