Getting Started

Prepare FaaS Environment

Please create at least one FaaS account among the following four provides. All of FaaS offers free plan.

Otherwise setup Apache OpenWhisk environment by yourself in either Docker or Kubernetes by refereeing to the steps described at the following sites.

Set Environment Variables

Build Image

Deploy Image

In case of Docker

ubuntu@trusty:~/faasshell[master]$ docker run -d -p 5984:5984 apache/couchdb

ubuntu@trusty:~/faasshell[master]$ make -e docker_image_prefix=YOUR_PREFIX run

ubuntu@trusty:~/faasshell[master]$ FAASSHELL_APIHOST=http://127.0.0.1:8080

ubuntu@trusty:~/faasshell[master]$ curl -ksLX GET ${FAASSHELL_APIHOST}/ -u $DEMO
{"version":"$Id rev.YYYY-MM-DD.COMMITID $"}

In case of Kubernetes

docker_image_prefix has to be your Docker Hub image prefix.

ubuntu@trusty:~/faasshell[master]$ kubectl create namespace faasshell

ubuntu@trusty:~/faasshell[master]$ kubectl -n faasshell run couchdb --image=apache/couchdb

ubuntu@trusty:~/faasshell[master]$ kubectl -n faasshell expose deployment couchdb --port=5984

ubuntu@trusty:~/faasshell[master]$ kubectl -n faasshell get pod
NAME                       READY     STATUS    RESTARTS   AGE
couchdb-69dbdcbb48-jzjz5   1/1       Running   0          1m

In case of proxy environment:

ubuntu@trusty:~/faasshell[master]$ kubectl -n faasshell get service | grep couchdb | awk '{print $3}'
10.101.62.31

ubuntu@trusty:~/faasshell[master]$ export NO_PROXY=$NO_PROXY,10.101.62.31
ubuntu@trusty:~/faasshell[master]$ make -e docker_image_prefix=YOUR_PREFIX deploy

ubuntu@trusty:~/faasshell[master]$ kubectl -n faasshell get pod
NAME                        READY     STATUS    RESTARTS   AGE
couchdb-69dbdcbb48-jzjz5    1/1       Running   0          15m
faasshell-cb657b84b-sct6x   1/1       Running   0          52s

ubuntu@trusty:~/faasshell[master]$ kubectl -n faasshell describe service faasshell | grep https | grep NodePort| awk '{print $3}' | cut -d'/' -f1
30954

ubuntu@trusty:~/faasshell[master]$ FAASSHELL_APIHOST=https://${cluster_address}:30954

ubuntu@trusty:~/faasshell[master]$ curl -ksLX GET ${FAASSHELL_APIHOST}/ -u $DEMO
{"version":"$Id rev.YYYY-MM-DD.COMMITID $"}

${cluster_address} depends on clusters environment, it is opened at https://$(minikube ip):30954 in case of Minikube.

The port number is changed each service deployment, 30954 is just an example.

Execute Hello World Example

Set DEMO key

ubuntu@trusty:~/faasshell[master]$ DEMO=ec29e90c-188d-11e8-bb72-00163ec1cd01:0b82fe63b6bd450519ade02c3cb8f77ee581f25a810db28f3910e6cdd9d041bf

Add hello function

faas interface

ubuntu@trusty:~/faasshell[master]$ curl -ksLX GET ${FAASSHELL_APIHOST}/faas/ -u $DEMO
[
  {
    "annotations": [ {"key":"exec", "value":"nodejs:6"} ],
    "name":"hello",
    "namespace":"demo",
    "publish":false,
    "version":"0.0.1"
  }
]

statemachine interface

ubuntu@trusty:~/faasshell[master]$ curl -ksLX GET ${FAASSHELL_APIHOST}/statemachine/hello_world_task.json \
-u $DEMO
{
  "asl": {
    "Comment":"A Hello World example of the Amazon States Language using an AWS Lambda function",
    "StartAt":"HelloWorld",
    "States": {
      "HelloWorld": {
        "End":true,
        "Resource":"frn:wsk:functions:::function:hello",
        "TimeoutSeconds":5,
        "Type":"Task"
      }
    }
  },
  "dsl":"fsm([task('HelloWorld',\"frn:wsk:functions:::function:hello\",[timeout_seconds(10)])])",
  "name":"hello_world_task.json",
  "namespace":"demo",
  "output":"ok"
}
ubuntu@trusty:~/faasshell[master]$ curl -ksX POST ${FAASSHELL_APIHOST}/statemachine/hello_world_task.json?blocking=true \
-u $DEMO
{
  "asl": {
    "Comment":"A Hello World example of the Amazon States Language using an AWS Lambda function",
    "StartAt":"HelloWorld",
    "States": {
      "HelloWorld": {
        "End":true,
        "Resource":"frn:wsk:functions:::function:hello",
        "TimeoutSeconds":5,
        "Type":"Task"
      }
    }
  },
  "dsl":"fsm([task('HelloWorld',\"frn:wsk:functions:::function:hello\",[timeout_seconds(10)])])",
  "input": {},
  "name":"hello_world_task.json",
  "namespace":"demo",
  "output": {"payload":"Hello, World!"}
}
ubuntu@trusty:~/faasshell[master]$ 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 an AWS Lambda function",
    "StartAt":"HelloWorld",
    "States": {
      "HelloWorld": {
        "End":true,
        "Resource":"frn:wsk:functions:::function:hello",
        "TimeoutSeconds":5,
        "Type":"Task"
      }
    }
  },
  "dsl":"fsm([task('HelloWorld',\"frn:wsk:functions:::function:hello\",[timeout_seconds(10)])])",
  "input": {"name":"Curl"},
  "name":"hello_world_task.json",
  "namespace":"demo",
  "output": {"payload":"Hello, Curl!"}
}
ubuntu@trusty:~/faasshell[master]$ curl -ksX PATCH ${FAASSHELL_APIHOST}/statemachine/hello_world_task.json \
-u $DEMO
digraph graph_name {
     "Start" -> "HelloWorld" ;
     "HelloWorld" -> "End" ;
}
ubuntu@trusty:~/faasshell[master]$ curl -ksX DELETE ${FAASSHELL_APIHOST}/statemachine/hello_world_task.json \
-u $DEMO
{"output":"ok"}

shell interface

ubuntu@trusty:~/faasshell[master]$ curl -ksLX GET ${FAASSHELL_APIHOST}/shell/hello_world_task.dsl \
-u $DEMO
{
  "dsl":"fsm([task('HelloWorld',\"frn:wsk:functions:::function:hello\",[timeout_seconds(10)])])",
  "name":"hello_world_task.dsl",
  "namespace":"demo",
  "output":"ok"
}
ubuntu@trusty:~/faasshell[master]$ curl -ksX POST  ${FAASSHELL_APIHOST}/shell/hello_world_task.dsl?blocking=true \
-H 'Content-Type: application/json' -d '{"input": {"name":"Shell"}}' -u $DEMO
{
  "dsl":"fsm([task('HelloWorld',\"frn:wsk:functions:::function:hello\",[timeout_seconds(10)])]).",
  "input": {"name":"Shell"},
  "name":"hello_world_task.dsl",
  "namespace":"demo",
  "output": {"payload":"Hello, Shell!"}
}
ubuntu@trusty:~/faasshell[master]$ curl -ksX DELETE ${FAASSHELL_APIHOST}/shell/hello_world_task.dsl \
-u $DEMO
{"output":"ok"}