Deploying and invoking

To deploy the newly built function, we use the faas-cli deploy command. It reads the function specification with -f, similar to other sub-commands. In this example, it uses the value of the provider's gateway to deploy the function. If there's already a previous function running as a service on Docker Swarm, the old one will be deleted before deploying the new one. After deployment, the URL for manually invoking the function, such as via curl, will be shown:

$ faas-cli deploy -f hello.yml 
Deploying: hello.
Removing old function.
Deployed.
URL: http://localhost:8080/function/hello

200 OK

To obtain all running functions on the cluster, we can run the faas-cli list command. The command also shows the number of invocations done on each function, and the number of replicas for function instances. The replicas will be increased automatically when the invocation rate gets high enough. All of this information is stored inside the instance of Prometheus. We will see it in a better way, with a Grafana dashboard, in the next section:

$ faas-cli list
Function Invocations Replicas
func_echoit 0 1
func_wordcount 0 1
func_webhookstash 0 1
func_markdown 0 1
func_hubstats 0 1
func_decodebase64 0 1
hello 0 1
func_base64 0 1
func_nodeinfo 0 1

The hello function accepts input via stdin and output via stdout. To test invocation of the function, a sentence is echoed and piped to the stdin of the command faas-cli invoke. This invocation is processed via the OpenFaaS framework, and all invocation stats are recorded on a Prometheus instance in the cluster:

$ echo "How are you?" | faas-cli invoke hello
Hello, Go. You said: How are you?
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset