Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Huawei Function Compute Serverless Plugin

This plugin enables Huawei Function Compute support within the Serverless Framework.

Getting started

Pre-requisites

  • Node.js 12.x or above
  • Serverless CLI v1.26.1+. You can run npm i -g serverless if you don't already have it.
  • An Huawei cloud account.

Create a new Function App

# Create Huawei Function App from template
# Templates include: huawei-nodejs
$ sls create -t huawei-nodejs -p <appName>
# Move into project directory
$ cd <appName>
# Install dependencies (including this plugin)
$ npm install

The serverless.yml file contains the configuration for your service.

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:

access_key_id=xxxxxxxx
secret_access_key=xxxxxxxxxxxxxxxxxxxx

Deploy Your Function App

# Deploy functions and events
$ sls deploy

# Deploy a function directly
$ sls deploy --param="function=hello"

# Deploy a trigger directly
$ sls deploy --param="trigger=TIMER"

Delete Your Function App

# Delete functions and events
$ sls remove

# Delete a function directly
$ sls remove --param="function=hello"

# Delete a trigger directly
$ sls remove --param="trigger=TIMER"

License

MIT

About

Provider plugin for the Serverless Framework which adds support for Huawei Cloud Functions.

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages