GithubHelp home page GithubHelp logo

raininfall / fun Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alibaba/funcraft

0.0 2.0 0.0 120 KB

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

License: MIT License

Makefile 2.22% JavaScript 97.78%

fun's Introduction

(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
Function compute(region):
  service service_name ok.
    function function_name ok.
API gateway(region):
    URL: POST http://<groupid>-<region>.alicloudapi.com/<the api path>
      => cn-hangzhou/service_name/function_name
      stage: RELEASE, deployed, version: 20171101125034887
      stage: PRE, deployed, version: 20171101125107780
      stage: TEST, deployed, version: 20171101144618017

Deploy to TEST & PRE stage:

$ fun deploy TEST
$ fun deploy PRE

Examples

Architect

See relationship of API Gateway & Function Compute:

Referrences

License

The MIT License

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.