Provider plugin for the Serverless Framework which adds support for Huawei Cloud Functions.
npm i -g serverless if you don't already have it.
bash
Create Huawei Function App from template
Templates include: huawei-nodejs
$ sls create -t huawei-nodejs -p
Move into project directory
$ cd
Install dependencies (including this plugin)
$ npm install
`
The serverless.yml file contains the configuration for your service.
`yaml
service: fg-service # service name
frameworkVersion: "3"
provider: # provider information
name: huawei
credentials: ~/.fg/credentials # 绝对地址,默认为 ~/credentials
runtime: Node.js14.18 # 可以指定华为云支持的Runtime, 默认Node.js14.18
# you can overwrite defaults here
# stage: dev # 阶段,默认为 dev
# package: default
# memorySize: 256 # 默认256M,优先级:函数设置>默认设置
# timeout: 30 # 默认30s,优先级:函数设置>默认设置
# region: cn-north-4 # 默认cn-north-4,优先级:函数设置>默认设置
# environment: # 环境变量,可选
# variables:
# ENV_FIRST: env1
# ENV_SECOND: env2
plugins:
- serverless-huawei-functions
functions:
hello_world:
handler: index.handler
# you can overwrite config here
# description: Huawei Serverless Cloud Function
# package: default
# memorySize: 256
# timeout: 30
# userData:
# ENV_FIRST: env1
# ENV_SECOND: env2
# events:
# - triggerTypeCode: TIMER
# status: ACTIVE
# eventData:
# name: Timer-b124
# schedule: 5m
# scheduleType: Rate
# userEvent: hello
`
In order to deploy this function, we need the credentials with permissions to access Huawei Function Compute.
Please create a credentials file and configure the credentials in it.
Here is an example credentials file:
`ini
access_key_id=xxxxxxxx
secret_access_key=xxxxxxxxxxxxxxxxxxxx
`
$3
`bash
Deploy functions and events
$ sls deploy
Deploy a function directly
$ sls deploy --param="function=hello"
Deploy a trigger directly
$ sls deploy --param="trigger=TIMER"
`
$3
`bash
Delete functions and events
$ sls remove
Delete a function directly
$ sls remove --param="function=hello"
Delete a trigger directly
$ sls remove --param="trigger=TIMER"
``