Giter Club home page Giter Club logo

naohirotamura / faasshell Goto Github PK

View Code? Open in Web Editor NEW
7.0 3.0 1.0 3.09 MB

FaaS Shell is a shell for Serverless Function Workflow across multiple clouds.

Home Page: https://naohirotamura.github.io/faasshell/

License: Apache License 2.0

Prolog 94.65% Shell 1.55% Makefile 1.72% Ruby 0.02% Python 0.30% Dockerfile 1.76%
faas serverless amazon-state-language aws-step-function aws-lambda google-cloud-functions azure-functions ibm-cloud-functions apache-openwhisk swi-prolog

faasshell's Introduction

CircleCI License

FaaS Shell is a shell for Serverless Function Workflow, which is a common abstraction layer on top of FaaS Infrastructures to execute multiple workflow languages across multiple clouds.

Faas Shell compiles workflow language and generate workflow DSL. Then FaaS Shell interpreter executes the workflow DSL. This architecture aims at enabling Multi Cloud Strategy which exploits the most attractive features from each provider beyond vendor agnostic solution.

Faas Shell also has REPL, which allows us to develop workflow interactively typing DSL directly into the prompt.

FaaS Shell currently supports one workflow language as the first step, and five FaaS infrastructures.

You can run your Amazon State Language workflow code created in AWS Step Functions in anywhere, and your workflow can call not only AWS Lambda but also functions in other FaaS Infrastructures.

Quick Start

  1. Create Serverless Function Workflow

    Create a Lambda State Machine by following AWS Step Functions tutorial. And save the statemachine as "hello_world_task.json".

    Assume "hello_world_task.json" looks like below except the region "us-east-2" and the account id "410388484666":

    {
       "Comment": "A Hello World example of the Amazon States Language using a Task state",
       "StartAt": "HelloWorld",
       "States": {
          "HelloWorld": {
             "Type": "Task",
             "Resource":"arn:aws:lambda:us-east-2:410388484666:function:hello",
             "End": true
          }
       }
    }

    The lambda function "arn:aws:lambda:us-east-2:410388484666:function:hello" is defined in Nodejs 6.10 as below:

    'use strict';
    
    console.log('Loading function');
    
    exports.handler = (event, context, callback) => {
        console.log('Received event:', JSON.stringify(event, null, 2));
        var name = event.name || 'World';
        callback(null, {payload:  'Hello, ' + name + '!'});
    };
  2. Set your AWS Access Keys to environment variables.

    How to get the AWS Access Keys is described in Managing Access Keys for Your AWS Account.

    $ export AWS_ACCESS_KEY_ID=AAAAAAAAAAAAAAAAAAAA
    $ export AWS_SECRET_ACCESS_KEY=BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
  3. Start Faas Shell

    $ docker run -d -p 5984:5984 apache/couchdb
    
    $ docker run -d --net=host -v /tmp:/logs \
                 -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
                 -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
                 nao16t/faasshell
    • Set the proxy environment variables if you are in private network.
      $ export HTTP_PROXY="http://id:[email protected]:8080"
      $ export HTTPS_PROXY="https://id:[email protected]:8433"
      $ export NO_PROXY="localhost,127.0.0.1,0.0.0.0,172.17.0.1"
    
      $ docker run -d --net=host -v /tmp:/logs \
                   -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
                   -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
                   -e HTTP_PROXY=$HTTP_PROXY \
                   -e HTTPS_PROXY=$HTTPS_PROXY \
                   -e NO_PROXY=$NO_PROXY \
                   nao16t/faasshell
  4. Execute the Serverless Function Workflow

    • Set the access information

      $ DEMO=ec29e90c-188d-11e8-bb72-00163ec1cd01:0b82fe63b6bd450519ade02c3cb8f77ee581f25a810db28f3910e6cdd9d041bf
      
      $ FAASSHELL_APIHOST=http://127.0.0.1:8080
    • Register "hello_world_task.json", then DSL is generated as the value of "dsl" key.

      $ curl -ksX PUT ${FAASSHELL_APIHOST}/statemachine/hello_world_task.json \
         -H 'Content-Type: application/json' -d @hello_world_task.json -u $DEMO
       {
         "asl": {
          "Comment":"A Hello World example of the Amazon States Language using a Task state",
          "StartAt":"HelloWorld",
          "States": {
            "HelloWorld": {
              "End":true,
              "Resource":"arn:aws:lambda:us-east-2:410388484666:function:hello",
              "Type":"Task"
            }
          }
        },
        "dsl":"fsm([task('HelloWorld',\"arn:aws:lambda:us-east-2:410388484666:function:hello\",[])])",
        "name":"hello_world_task.json",
        "namespace":"demo",
        "output":"ok"
      }
    • Execute the DSL, the result is returned as the value of the output key.

      $ curl -ksX POST ${FAASSHELL_APIHOST}/statemachine/hello_world_task.json?blocking=true \
        -H 'Content-Type: application/json' -d '{"input": {"name": "Curl"}}' -u $DEMO
       {
        "asl": {
          "Comment":"A Hello World example of the Amazon States Language using a Task state",
          "StartAt":"HelloWorld",
          "States": {
            "HelloWorld": {
              "End":true,
              "Resource":"arn:aws:lambda:us-east-2:410388484666:function:hello",
              "Type":"Task"
            }
          }
        },
        "dsl":"fsm([task('HelloWorld',\"arn:aws:lambda:us-east-2:410388484666:function:hello\",[])])",
        "input": {"name":"Curl"},
        "name":"hello_world_task.json",
        "namespace":"demo",
        "output": {"payload":"Hello, Curl!"}
      }

Quick Start showed just AWS Lambda case. Other FaaS provider cases are covered by Getting started.

Getting started also explains how to deploy function making use of each provider's CLI, how to build and deploy FaaS Shell, how to use REST API, and etc.

Samples directory contains some examples in each provider's sub-directory based on the following State Machine Template.

Demo

  • Hello Multiple Clouds

    This demonstrates that one state machine calls hello function of each FaaS provider in sequential or in parallel.

  • IFTTT as FaaS

    This demonstrates that the statemachine invokes IFTTT Applet as a task and saves the result into Google sheets.

  • IFTTT as FaaS in REPL

    This shows how to execute the above "IFTTT as FaaS" demo in REPL, interactive shell environment.

  • Activity Task

    This demonstrates how a long running process hosted outside of FaaS interacts with Activity Task State.

  • Event State

    Event State is an extention of Amazon State Language. This demonstrates how an event triggers function in Event State.

  • Translation Service Evalution

    In case of Artificial Intelligence services, specific service has different characteristics, strength and weakness, each other among providers. As an example, this demo presents translation service evaluation workflow among providers using an ambiguous sentence.

Devloper's Guide (work in progress)

Reference (work in progress)

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.