Skip to content

tuapuikia/fun

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

(have)Fun with Serverless

It's a fun thing to programing with API Gateway & Function Compute.

Installation

You can install it as a command line tool via NPM/yarn/CNPM

$ npm install @alicloud/fun

Usage

The fun tool use faas.yml to describe the API Gateway & Function Compute things, then publish it online.

faas.yml

The fun tool think a folder with faas.yml as a Serverless project. faas.yml describe these things:

  • credentials
  • role
  • function compute
  • api gateway

credentials

Includes account id, access key id, access key secret. It's optional. If not specificated by faas.yml, get it from environment variable.

# faas.yml
accountid: '<account id, default is process.env.ACCOUNT_ID>'
accessKeyId: '<ACCESS KEY ID, default is process.env.ACCESS_KEY_ID>'
accessKeySecret: '<ACCESS KEY SECRET, default is process.env.ACCESS_KEY_SECRET>'

role

Give API Gateway right to access Function Computed. Optional.

# faas.yml
role:
  name: 'apigatewayAccessFC'

Function Compute

Write your function into hello.js with:

'use strict';

const hook = require('fc-helper');

exports.index = hook((req, res) => {
  res.send('Hello world!\n');
});

The helper.js can be found at here.

Describe it in faas.yml:

# faas.yml
function-compute:
  region: 'cn-shanghai'
  services:
    - name: 'fc'
      description: 'fc test'
      functions:
        - name: 'helloworld'
          description: 'hello!'
          # entry point
          handler: hello.index
          # which files should be ziped
          codes:
            - 'hello.js'

API Gateway

exports the functions with API Gateway:

# faas.yml
api-gateway:
  endpoint: 'http://apigateway.cn-hangzhou.aliyuncs.com'
  groups:
    - name: 'apigw_fc'
      description: 'API Gateway & Function Compute'
      apis:
        - name: 'helloworld'
          method: 'GET'
          path: '/helloworld'
          function: 'cn-shanghai/fc/helloworld'

Upload & deploy

Use fun command to upload & deploy it to AliCloud:

$ fun deploy

Examples

Architect

See relationship of API Gateway & Function Compute:

Referrences

License

The MIT License

About

(have) Fun with Serverless(API Gateway & Function Compute)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • JavaScript 97.7%
  • Makefile 2.3%