1 Star 0 Fork 0

Serverless Devs Awesome / apigateway-tencent-component

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

前言

通过本组件,您可以简单快速的部署腾讯云API网关。

使用

最简使用方法

模版拉取:

s init apigateway -p tencent

其中Yaml的默认配置为:

MyAPIGateway:
  Component: apigateway
  Provider: tencent
  Properties:
    Region: ap-shanghai
    Service:
      Name: serverless
      Description: the serverless service
    API:
        - Path: '/'
          Protocol: HTTP
          Method: GET
          Name: 'mock-api'
          ServiceType: MOCK
          ServiceMockReturnMessage: 'Hello Serverless Devs Tool'

完整Yaml示例

MyAPIGateway:
  Component: apigateway
  Provider: tencent
  Access: release
  Properties:
    Region: ap-shanghai
    Service:
      Id: service-8dsikiq6
      Name: serverless
      Protocols:
        - http
        - https
      Description: the serverless service
      Environment: release
      NetTypes:
        - OUTER
        - INNER
      Domains:
        - Domain: abc.com
          # 如要添加https,需先行在腾讯云-SSL证书进行认证获取cettificateId
          CertificateId: abcdefg
          # 如要设置自定义路径映射,请设置为 false
          IsDefaultMapping: false
          PathMappingSet:
            - Path: /
              Environment: release
          Protocols:
            - http
            - https
    API:
        # 前端类型: WEBSOCKET, 后端类型: SCF
        - Path: /
          Method: GET
          Protocol: WEBSOCKET
          Function:
            # 前端类型为WEBSOCKET且后端为SCF时, transportFunctionName 为必填
            TransportFunctionName: myFunction
            RegisterFunctionName: myFunction
            CleanupFunctionName: myFunction
        # 前端类型: WEBSOCKET, 后端类型: HTTP
        - Path: /ws
          Protocol: WEBSOCKET
          Name: 'test-ws'
          Method: GET
          ServiceType: WEBSOCKET
          ServiceConfig:
            Url: 'ws://www.test.com'
            Path: /
            Method: GET
        # 前端类型: HTTP, 后端类型: SCF
        - Path: /test/{abc}/{cde}
          Id: api-id
          Method: GET
          Description: Serverless REST API
          EnableCORS: TRUE
          ResponseType: HTML
          ServiceTimeout: 10
          Parameters:
            - Name: abc
              Position: PATH
              Required: 'TRUE'
              Type: string
              DefaultValue: abc
              Description: mytest
            - Name: cde
              Position: PATH
              Required: 'TRUE'
              Type: string
              DefaultValue: abc
              Description: mytest
          Function:
            IsIntegratedResponse: true
            FunctionQualifier: $LATEST
            FunctionName: myFunction
          UsagePlan:
            UsagePlanId: 1111
            UsagePlanName: slscmp
            UsagePlanDesc: sls create
            MaxRequestNum: 1000
          Auth:
            SecretName: secret
            SecretIds:
              - AKIDNSdvdFcJ8GJ9th6qeZH0ll8r7dE6HHaSuchJ
        # 前端类型: HTTP, 后端类型: MOCK
        - Path: /mo
          Protocol: HTTP
          Method: GET
          Name: 'mock-api'
          ServiceType: MOCK
          ServiceMockReturnMessage: 'mock response content'
        # 前端类型: HTTP, 后端类型: HTTP
        - Path: /rest
          Protocol: HTTP
          Name: 'test-http'
          Method: GET
          ServiceType: HTTP
          ServiceConfig:
            Url: 'http://www.test.com'
            Path: /test
            Method: GET

详细使用方法

参数名 必填 类型 参数描述
Region true Enum 地域
Service false Struct API网关服务
API false Struct API详细信息

Service

参数 必填 参数类型 默认值 描述
Id false String 服务的全局唯一 ID,由系统生成
Protocols true List ['http'] 服务的前端请求类型,例如 HTTP,HTTPS,HTTP 和 HTTPS。 (http / https)
Name false String 用户自定义的服务名称。 如果该参数未传递,则由系统自动生成一个唯一名称
NetTypes false List ['OUTER'] 网络类型列表,用于指定支持的访问类型,INNER 为内网访问,OUTER 为外网访问。
Description false String 用户自定义的服务描述说明
Environment false String 服务要发布的环境的名称,支持三种环境: test(测试)、prepub(预发布)、 release(发布)
Domains false List [] 自定义 API 域名,配置参数参考customDomain
Domains
参数 必填/可选 参数类型 默认值 描述
Domain true String 需要绑定的自定义域名
CertificateId false String 自定义域名的证书,如果设置为 https,则为必需。
IsDefaultMapping false Boolean true 是否使用默认路径映射。 如果要自定义路径映射,请设为false
PathMappingSet false Struct [] 自定义路径映射, 当 isDefaultMappingfalse 时必填,配置参数参考pathMappingSet
Protocols false List 绑定自定义域协议类型,例如 HTTP,HTTPS,HTTP 和 HTTPS,默认与前端协议相同
PathMappingSet
参数名 必填 类型 参数描述
path false String 自定义映射路径
environment false String 自定义映射环境

API

参数 必填/可选 类型 默认值 描述
Id false String API 的唯一 ID
Protocol false List HTTP 指定的前端 API 类型, 默认为HTTP,如要创建 websocket 类型的 API,请设为WEBSOCKET
Path true String API 路径
Method true String 请求方法
ServiceType false String SCF 指定的后端类型,默认为 SCF,如要创建 mock 或 http 的类型,可设为 MOCKHTTP
Description false String API 描述
EnableCORS false Boolean false 是否启用跨域访问。 true:启用, false:不启用
Function false Struct 对应的 Serverless 云函数,配置参数参考function
UsagePlan false Struct 基于 API 维度的使用计划,配置参数参考usagePlan
Auth false Struct API 鉴权设置,配置参数参考auth
ServiceTimeout false Number API 的后端服务超时时间,单位为秒
ResponseType false String 返回类型: HTML、JSON、TEST、BINARY、XML
Parameters false List 前端请求参数,配置参数参考param
ServiceConfig false Struct API 的后端服务配置,配置参数参考serviceConfig
ServiceMockReturnMessage false String Mock 接口类型返回结果,如果 serviceType 设置为 MOCK,此参数必填
Function
参数 描述
IsIntegratedResponse 是否开启响应集成,当前端类型为HTTP时生效
FunctionQualifier scf 函数版本
FunctionName API 的后端服务的 SCF 函数的名称,当前端类型为HTTP时生效且为必填
TransportFunctionName API 的后端服务的传输函数的名称,当前端类型为WEBSOCKET时生效且为必填
RegisterFunctionName API 的后端服务的注册函数的名称,当前端类型为WEBSOCKET时生效
CleanupFunctionName API 的后端服务的清理函数的名称,当前端类型为WEBSOCKET时生效
ServiceConfig
参数 描述
Url API 的后端服务 url
Path API 的后端服务路径
Method API 的后端服务请求方法
UsagePlan
参数 描述
UsagePlanId 用户自定义的基于 API 的使用计划 ID
UsagePlanName 用户自定义的基于 API 的使用计划名称
UsagePlanDesc 用户自定义的基于 API 的使用计划描述
MaxRequestNum 允许的请求总数。不传该参数时默认为 1000 次,若其保留为空,则默认情况下将使用-1,表示已禁用
Auth
参数 描述
SecretName 用户自定义的密钥名称
SecretIds 用户自定义的 secretID。当类型为手动时需要。 它可以包含 5 到 50 个字母,数字和下划线。
Parameters
参数 描述
Name 请求参数名称
Position 参数位置,仅支持PATHQUERYHEADER类型
Type 参数类型,如 String 和 int.
DefaultValue 参数默认值
Required 参数是否必填, true: 必填; false: 可选
Description 参数备注/描述
MIT License Copyright (c) 2020 Serverless Devs Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

暂无描述 展开 收起
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/serverless-devs-awesome/apigateway-tencent-component.git
git@gitee.com:serverless-devs-awesome/apigateway-tencent-component.git
serverless-devs-awesome
apigateway-tencent-component
apigateway-tencent-component
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891