@serverless/tencent-framework

0.1.4 • Public • Published

腾讯云 Framework Serverless Component

npm NPM downloads

简体中文 | English

简介

腾讯云 Framework Serverless Component,为框架类型组件提供基层管理部署云 Baas 产品能力,基于 Framework 组件,你可以非常轻松封装框架级别的组件。

目录

  1. 安装
  2. 配置
  3. 部署
  4. 移除

1. 安装

通过 npm 全局安装 serverless cli

$ npm install -g serverless

2. 配置

在项目根目录创建 serverless.yml 文件,在其中进行如下配置

$ touch serverless.yml
# serverless.yml
myFramework:
  component: '@serverless/tencent-framework'
  inputs:
    framework: test
    functionName: framework-function
    region: ap-guangzhou
    handler: app.handler
    runtime: Nodejs8.9
    code: ./
    functionConf:
      timeout: 30
      memorySize: 128
    environment:
      variables:
        RUN_ENV: test
    apigatewayConf:
      protocols:
        - http
        - https
      environment: release

3. 部署

3.1 构建静态资源

$ npm run build

3.2 部署到云端

如您的账号未 登陆注册 腾讯云,您可以直接通过 微信 扫描命令行中的二维码进行授权登陆和注册。

通过 sls 命令进行部署,并可以添加 --debug 参数查看部署过程中的信息

$ sls --debug

  DEBUG ─ Resolving the template's static variables.
  DEBUG ─ Collecting components from the template.
  DEBUG ─ Downloading any NPM components found in the template.
  DEBUG ─ Analyzing the template's components dependencies.
  DEBUG ─ Creating the template's components graph.
  DEBUG ─ Syncing template state.
  DEBUG ─ Executing the template's components graph.
  DEBUG ─ Compressing function framework-function file to /Users/yugasun/Desktop/Develop/serverless/tencent-framework/example/.serverless/framework-function.zip.
  DEBUG ─ Compressed function framework-function file successful
  DEBUG ─ Uploading service package to cos[sls-cloudfunction-ap-guangzhou-code]. sls-cloudfunction-default-framework-function-1584093126.zip
  DEBUG ─ Uploaded package successful /Users/yugasun/Desktop/Develop/serverless/tencent
-framework/example/.serverless/framework-function.zip
  DEBUG ─ Creating function framework-function
  framework-function [████████████████████████████████████████] 100% | ETA: 0s | Speed: 3.83k/s
  DEBUG ─ Updating code...
  DEBUG ─ Updating configure...
  DEBUG ─ Created function framework-function successful
  DEBUG ─ Setting tags for function framework-function
  DEBUG ─ Creating trigger for function framework-function
  DEBUG ─ Deployed function framework-function successful
  DEBUG ─ Starting API-Gateway deployment with name ap-guangzhou-apigateway in the ap-guangzhou region
  DEBUG ─ Using last time deploy service id service-jflj67ms
  DEBUG ─ Updating service with serviceId service-jflj67ms.
  DEBUG ─ Endpoint ANY / already exists with id api-7hwektu6.
  DEBUG ─ Updating api with api id api-7hwektu6.
  DEBUG ─ Service with id api-7hwektu6 updated.
  DEBUG ─ Deploying service with id service-jflj67ms.
  DEBUG ─ Deployment successful for the api named ap-guangzhou-apigateway in the ap-guangzhou region.

  myFramework:
    functionName:        framework-function
    cns:                 (empty array)
    region:              ap-guangzhou
    apiGatewayServiceId: service-jflj67ms
    url:                 https://service-jflj67ms-1251556596.gz.apigw.tencentcs.com/release/

  17s › myFramework › done

注意: slsserverless 命令的简写。

4. 移除

通过以下命令移除部署的 API 网关

$ sls remove --debug

  DEBUG ─ Flushing template state and removing all components.
  DEBUG ─ Removed function framework-function successful
  DEBUG ─ Removing any previously deployed API. api-7hwektu6
  DEBUG ─ Removing any previously deployed service. service-jflj67ms

  7s › myFramework › done

账号配置(可选)

当前默认支持 CLI 扫描二维码登录,如您希望配置持久的环境变量/秘钥信息,也可以本地创建 .env 文件

$ touch .env # 腾讯云的配置信息

.env 文件中配置腾讯云的 SecretId 和 SecretKey 信息并保存

如果没有腾讯云账号,可以在此 注册新账号

如果已有腾讯云账号,可以在 API 密钥管理 中获取 SecretIdSecretKey.

# .env
TENCENT_SECRET_ID=123
TENCENT_SECRET_KEY=123

更多组件

可以在 Serverless Components repo 中查询更多组件的信息。

Package Sidebar

Install

npm i @serverless/tencent-framework

Weekly Downloads

1

Version

0.1.4

License

Apache-2.0

Unpacked Size

38.6 kB

Total Files

7

Last publish

Collaborators