Defining and invoking a function with the UI

It is really simple to define and invoke a function on OpenFaaS. After pushing the image, a function can be defined via the OpenFaaS UI Portal. First, open http://127.0.0.1:8080/ui. Then, you will see a clickable label, CREATE NEW FUNCTION, in the left panel. After clicking it, dialog for defining a function will pop up. It requires the Docker image name for this function; in this case, the image name will be chanwit/func_c. Again, please do not forget to change my Docker ID to yours. Second, the definition requires a function name. Just name it func_c. Third, we need to define the value for the fprocess field pointing to the command line to invoke the binary program. In this example, the command line will simply be /usr/bin/func_c inside the container. If the function program requires some parameters, also include them there. Finally, the function definition requires the name of a Docker overlay network to allow the API gateway to connect to the function containers. Just include the default one, func_functions, there. It is really important to note that if an OpenFaaS stack is deployed to another environment, and has a different overlay network name, you must not forget to specify the correct one:

Figure 4.8: Defining an OpenFaaS function via the UI

If everything looks fine, click CREATE to define the function. After creation, the func_c function will be listed in the left panel. Clicking on the function's name will show the main panel for function invocation, as follows:

 
Figure 4.9: Invocation of the func_c function with its response body

If a function requires any input, the input data in the form of text or JSON can be placed as the Request body. However, the func_c function does not accept any input, so just press the INVOKE button and the function will be called. In the example, the invocation process is completed and its status is OK: 200. The API gateway gets the STDOUT from the function's binary, /usr/bin/func_c, and shows it here as the Response body in text format.

..................Content has been hidden....................

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