Skip to content

Latest commit

 

History

History
342 lines (271 loc) · 18.2 KB

configure.md

File metadata and controls

342 lines (271 loc) · 18.2 KB

配置文档

全部配置

# serverless.yml
component: http # (必选) 组件名称
name: webDemo # 必选) 组件实例名称.

inputs:
  region: ap-guangzhou # 云函数所在区域
  src: # 部署src下的文件代码,并打包成zip上传到bucket上
    src: ./ # 本地需要打包的文件目录
    exclude: # 被排除的文件或目录
      - .env
      - 'node_modules/**'
  # src: # 在指定存储桶bucket中已经存在了object代码,直接部署
  #   bucket: bucket01 # bucket name,当前会默认在bucket name后增加 appid 后缀, 本例中为 bucket01-appid
  #   object: cos.zip  # bucket key 指定存储桶内的文件
  faas: # 函数配置相关
    framework: express
    runtime: Nodejs12.16
    name: webDemo # 云函数名称
    timeout: 10 # 超时时间,单位秒
    memorySize: 512 # 内存大小,单位MB
    environments: #  环境变量
      - key: envKey
        value: envValue
    vpc: # 私有网络配置
      vpcId: 'vpc-xxx' # 私有网络的Id
      subnetId: 'subnet-xxx' # 子网ID
    layers:
      - name: layerName #  layer名称
        version: 1 #  版本
    tags:
      - key: tagKey
        value: tagValue
  apigw: #  # http 组件会默认帮忙创建一个 API 网关服务
    isDisabled: false # 是否禁用自动创建 API 网关功能
    id: service-xxx # api网关服务ID
    name: serverless # api网关服务ID
    api: # 创建的 API 相关配置
      cors: true #  允许跨域
      timeout: 15 # API 超时时间
      name: apiName # API 名称
      qualifier: $DEFAULT # API 关联的版本
    protocols:
      - http
      - https
    environment: test
    tags:
      - key: tagKey
        value: tagValue
    customDomains: # 自定义域名绑定
      - domain: abc.com # 待绑定的自定义的域名
        certId: abcdefg # 待绑定自定义域名的证书唯一 ID
        # 如要设置自定义路径映射,(customMap = true isDefaultMapping = false)必须两者同时出现 其余情况都是默认路径
        customMap: true
        isDefaultMapping: false
        # 自定义路径映射的路径。使用自定义映射时,可一次仅映射一个 path 到一个环境,也可映射多个 path 到多个环境。并且一旦使用自定义映射,原本的默认映射规则不再生效,只有自定义映射路径生效。
        pathMap:
          - path: /
            environment: release
        protocols: # 绑定自定义域名的协议类型,默认与服务的前端协议一致。
          - http # 支持http协议
          - https # 支持https协议
    app: #  应用授权配置
      id: app-xxx
      name: app_demo
      description: app description
  # 通常用于将文件上传至cos做备份,访问还是通过网关访问
  assets:
    cos:
      bucket: static-bucket
      sources:
        - src: public
          targetDir: /
    cdn:
      area: mainland
      domain: abc.com
      autoRefresh: true
      refreshType: delete
      forceRedirect:
        switch: on
        redirectType: https
        redirectStatusCode: 301
      https:
        http2: on
        certId: 'abc'

inputs 配置参数

主要的参数

参数名称 必选 类型 默认值 描述
region string ap-guangzhou 项目部署所在区域
src Src process.cwd() 项目代码配置
faas Faas 函数配置
apigw Apigw API 网关配置
assets Assets 静态资源 CDN 配置

Src

项目代码配置

参数名称 是否必选 类型 默认值 描述
src string 代码路径。与 object 不能同时存在。
exclude string[] 不包含的文件或路径, 遵守 glob 语法
bucket string bucket 名称。如果配置了 src,表示部署 src 的代码并压缩成 zip 后上传到 bucket-appid 对应的存储桶中;如果配置了 object,表示获取 bucket-appid 对应存储桶中 object 对应的代码进行部署。
object string 部署的代码在存储桶中的路径。

Faas

函数配置

参数名称 是否必选 类型 默认值 描述
framework string 项目框架名称,比如 express
runtime string Nodejs12.16 运行环境
name string 函数名称
timeout number 10 函数最长执行时间,单位为秒,可选值范围 1-900 秒,默认为 3 秒
memorySize number 512 函数运行时内存大小,默认为 128M,可选范围 64、128MB-3072MB,并且以 128MB 为阶梯
environments Environment[] 函数的环境变量
vpc Vpc 函数的 VPC 配置
layers Layer[] 云函数绑定的 layer
tags Tag[] 标签配置

此处只是列举,faas 参数支持 scf 组件的所有基础配置( events 除外)

framework 支持的框架如下:

  • express
  • koa
  • egg
  • nextjs
  • nuxtjs
  • nestjs
  • flask
  • django
  • laravel
  • thinkphp (暂不支持)
Layer

层配置

参数名称 是否必选 类型 默认值 描述
name string 层名称
version string 层版本号
Environment

环境变量

参数名称 类型 描述
key string 环境变量参数, 键
value string 环境变量参数, 值
Vpc

VPC 配置

参数名称 类型 描述
vpcId string 私有网络 ID
subnetId string 子网 ID

Apigw

API 网关配置

参数名称 是否必选 类型 默认值 描述
id string API 网关服务 ID, 如果存在将使用这个 API 网关服务
name string serverless API 网关服务名称, 默认创建一个新的服务名称
protocols string[] ['http'] 前端请求的类型,如 http,https,http 与 https
environment string release 发布环境. 网关环境: test, prepub 与 release
usagePlan UsagePlan 使用计划配置
auth ApiAuth API 密钥配置
customDomains CustomDomain[] 自定义 API 域名配置
enableCORS boolean false 开启跨域。默认值为否。
isDisabled boolean false 关闭自动创建 API 网关功能。默认值为否,即默认自动创建 API 网关。
api Api API 配置
tags Tag[] 标签配置
ignoreUpdate boolean false 忽略 API 网关更新
Api
参数名称 是否必选 类型 默认值 描述
name string http_api 名称,校验规则:最长 50 个字符,支持 a-z,A-Z,0-9
timeout number 15 Api 超时时间,单位: 秒,时间范围:1-1800 秒
cors boolean true 是否支持跨域
qualifier string $DEFAULT 关联的函数版本
UsagePlan

使用计划配置

参考: https://cloud.tencent.com/document/product/628/14947

参数名称 是否必选 类型 描述
usagePlanId string 用户自定义使用计划 ID
usagePlanName string 用户自定义的使用计划名称
usagePlanDesc string 用户自定义的使用计划描述
maxRequestNum number 请求配额总数,如果为空,将使用-1 作为默认值,表示不开启
ApiAuth

API 密钥配置

参数名称 类型 描述
secretName string 密钥名称
secretIds string 密钥 ID
CustomDomain

自定义域名配置

参数名称 是否必选 类型 默认值 描述
domain string 待绑定的自定义的域名。
protocol string[] 绑定自定义域名的协议类型,默认与服务的前端协议一致。
certId string 待绑定自定义域名的证书 ID,如果设置了 protocol 含有 https,则为必选
isDefaultMapping string true 是否使用默认路径映射。为 false 时,表示自定义路径映射,此时 pathMappingSet 必填。
pathMappingSet PathMap[] [] 自定义路径映射的路径。
isForcedHttps boolean false 是否启用Https强制重定向功能

注意:使用自定义映射时,可一次仅映射一个 path 到一个环境,也可映射多个 path 到多个环境。并且一旦使用自定义映射,原本的默认映射规则不再生效,只有自定义映射路径生效。

PathMap

自定义路径映射

参数名称 是否必选 类型 Description
path string 自定义映射路径
environment string 自定义映射环境,有效值:test、prepub 和 release

Assets

静态资源配置

参数名称 是否必选 类型 默认值 描述
cos Cos COS 配置
cdn Cdn CDN 配置
Cos

COS 配置

参数名称 是否必选 类型 默认值 描述
bucket string COS 存储同名称
sources Source[] [{ "src": "public", "targetDir": "/" }] 需要托管到 COS 的静态资源目录
ignoreUpdate boolean false 忽略 COS 网关更新
Source

静态资源目录配置

参数名称 是否必选 类型 默认值 描述
src string 静态资源目录
targetDir string / 上传到 COS 存储桶目录

nextjs 组件默认 sources 配置为:

[
  { "src": ".next/static", "targetDir": "/_next/static" },
  { "src": "public", "targetDir": "/" }
]

nuxtjs 组件默认 sources 配置为:

[
  { "src": ".nuxt/dist/client", "targetDir": "/_next/static" },
  { "src": "public", "targetDir": "/" }
]
Cdn

CDN 配置

area: mainland domain: cnode.yuga.chat autoRefresh: true refreshType: delete forceRedirect: switch: on redirectType: https redirectStatusCode: 301 https: http2: on certId: 'eGkM75xv'

参数名称 是否必选 类型 默认值 描述
domain string CDN 域名
area string mainland 加速区域,mainland: 大陆,overseas:海外,global:全球加速
autoRefresh boolean true 是否自动刷新 CDN
refreshType string delete CDN 刷新类型,delete:刷新全部资源,flush:刷新变更资源
forceRedirect ForceRedirect 访问协议强制跳转配置
https Https https 配置
ignoreUpdate boolean false 忽略 CDN 更新
ForceRedirect

访问协议强制跳转配置

参数名称 是否必选 类型 默认值 描述
switch string on 访问强制跳转配置开关, on:开启,off:关闭
redirectType string https 访问强制跳转类型,http:强制 http 跳转,https:强制 https 跳转
redirectStatusCode number 301 强制跳转时返回状态码,支持 301、302
Https

HTTPS 配置

参数名称 是否必选 类型 默认值 描述
certId string 腾讯云托管域名证书 ID
http2 string 是否开启 HTTP2,on: 开启,off: 关闭

Tag

标签配置

参数名称 是否必选 类型 默认值 描述
key string
value string