Oracle Function was announced late last year (2018), with limited availability to select Oracle Cloud customers. The platform is built on Fn and is Oracle’s solution for developers wanting to deploy services using a Serverless Framework.
As succinctly explained by Kaslin Fields, a Fn function is a small embodiment of code that listens and speaks to HTTP streams. Ideally, each Fn function serves one, and only one purpose. It can be implemented in wide variety of programming languages and they are listed here (see the list of runtime options available).
The Fn project provides a concise set of instructions on installing the Fn command line interface (CLI) utility. The CLI allows developers to run a Fn server locally, and perform developer and deployment client functions.
A rather recent version of Docker is required, and if you are on a Microsoft Windows machine, I highly recommend installing Virtual Box and running a Linux virtual machine (VM) for Fn development. You can create a VM manually, or you can install Vagrant and quickly stand up a suitable using Oracle’s official Vagrant build scripts (see Orace Linux 7 with Docker engine).
In a nutshell, assuming a Linux Operating System (OS), do the following:
Install, configure and run Docker.
Install Fn CLI using the command provided:
$ curl -LSs https://raw.githubusercontent.com/fnproject/cli/master/install | sh
Open a console and start the Fn Server for local development:
$ fn start
This pulls a Docker image and runs a container. The default server API URL is
Configure the VM to work with a local registry if you are planning to start out by developing serverless functions locally.
Follow the quick tutorial on creating a simple “Helloworld” service, changing the runtime to use the programming language of your choice.
Oracle Functions is not 100% ready to go, right out of the box when your Oracle Cloud account is provisioned. The setup tasks and deployment instructions are already available in the official documentation. I shall attempt to summarise and highlight the important steps.
A minimally functional Virtual Cloud Network (VCN)
Policies that allows Oracle Functions (FaaS) to:
a. Access the Oracle Cloud Infrastructure Registry (OCIR); and
Allow service FaaS to read repos in tenancy
b. Use network components in the target compartment.
Allow service FaaS to use virtual-network-family in compartment <COMPARTMENT_NAME>
One or two policies may be created, however, the first policy statement must be created in a policy within the root compartment.
There are ten steps to perform for configuring the Fn development environment. The minimum you will need to invoke a simple “Helloworld” function are:
- Setting up the OCI API Signing key .
opensslcommand to generate the private and public keys. Note down the paths and passphrase used.
- Add the public key to the OCI user’s API Keys and then noting the fingerprint.
- Create the OCI profile and configuration file (
~/.oci/config). Make sure the values required are entered correctly, or API signing will fail and you will not be able to authenticate with the endpoint. Note the profile name. The end result is a profile like this:
oci-curl, which isn’t really required to do a quick invocation test.
- If you already have a Fn development environment, then chances are, Docker and Fn CLI are already installed, configured and running.
- Setup the context (and this) for Fn CLI to work with Oracle Functions. After performing these steps, a context file will be created in
~/.fn/contexts, containing contents similar to this:
- Generate and note the Auth token, and then login to the OCIR.
The best way to check that the environment is configured (
~/.oci/config) correctly, is to list the applications available:
$ fn list apps
To create an application, either use the OCI console:
Or, use the Fn CLI, specifying the name of the application, and the OCID of the subnet to attach to:
$ fn create app nodeapp --annotation oracle.com/oci/subnetIds='["ocid1.subnet.oc1.iad.**********"]'
List the applications again to ensure it was successfully created:
$ fn list apps
Following the Fn tutorial, you would have created a directory containing the following artifacts required for a Fn function:
Set your working directory here and then attempt to deploy the application:
[/home/myuser/projects/nodefn]$ fn -v deploy --app nodeapp
With increase verbosity, it is clear that Docker is used to containerize the service. I have not delved into the nuts and bolts of the deployment model, but from the little I know, a Docker image is first created and deployed to the OCIR. When a function is invoked, the platform creates a container, executes the function and then terminates, releasing any allocated resources.
To invoke the function, simply execute the command or use the
oci-curl if available:
[/home/myuser/projects/nodefn]]$ fn invoke nodeapp nodefn
The tutorial’s “Helloworld” example doesn’t do much for now. However, as mentioned earlier in this article, Fn functions are wrapped up in a Docker container. By creating a custom
Dockerfile for your Fn, the possibilities are endless.
Also in the tutorials, the authors provide a roadmap on how to create a custom Docker image that uses ImageMagick to perform image manipulations. Something that could be useful to us Oracle Application Express developers when Oracle Multimedia is completely removed in future Oracle Database versions.