Oracle Functions. A first impression
I’ve been working with the Oracle Fn project for about a year, now. I really liked the project since my first contact with it. It was back in December 2017, I was on vacations and decided to get into something new. I remember it was a morning in Cancun, and while my family was deciding where to go, I downloaded the fn project and created my first functions using Go, Python and Java.
It was pretty straight forward to install it and deploy functions, I actually started to say in my presentations that I can challenge anyone to start using it and if in less than five minutes you don’t have a first function deploy, I pay for your dinner.
You can try it yourself, just go here and follow the instructions: http://http://fnproject.io/
I can bet you that in less than five minutes you will have your first function deployed. The only pre-requisite is to have Docker installed in your server.
As I mentioned, I started to use the Fn project back in 2017. During 2018, I delivered some presentations about the platform while participating in the Developer Community Tour Latinamerica, and then in Open World San Francisco, I also (together with Leonardo González) presented a demo and some slides about Fn Project.
Then at the end of 2018, I received the news that the platform was about to go GA, and there was a chance to get an early access to test the product and share hour thoughts with the Product Management Team. I just did that and I have very good impressions about the platform.
Oracle Functions is a serverless offering and it runs on top of the Oracle Cloud Infrastructure. For the early access (I guess that will change once it goes GA), I had to provision some resources on top of my OCI service:
a) Create a compartment where all the artifcats will be stored
b) Create a user to manage that compartment
c) Create a Virtual Network, as wel a Subnets
d) Create a set of policies to be able to manage and control OCI resources
Once you provision those elements, you will have the Oracle Functions service ready to serve your functions.
And at the end, due to this is a Serverless platform, whatever is behind the scenes should not be our first concern. Our first concern should be to develop, and the rest, for example the infrastructure, will be handled by the cloud provider, in this case: Oracle.
We will be focusing in develop and use our functions, but where it is deployed and what type of infrastructure is supporting it, it is definitely relevant, but not our concern. It is serverless, and that is the approach we should take.
The interface looks like this:
An application will contain one or more functions. In this case I have two applications, each of those contain one function.
In my case, I have provisioned a Digital Ocean Ubuntu box from where I installed Docker and the Fn CLI.
To install the CLI, it is as simple as:
$ curl -LSs https://raw.githubusercontent.com/fnproject/cli/master/install | sh
And then, just test it:
$ fn version
That should give you:
Then you need to copy the OCID of the compartment that you created in previous steps, you will get that from here:
With that copied, you will perform a set of steps to configure the Fn CLI to point to your Oracle Functions instance service. Those steps are the following:
Create a new Fn Project CLI context (you decide the name):
$ fn create context <my-context> — provider oracle
Use the previously created context:
$ fn use context <my-context>
Tell the context that you want to work in the compartment that we created previously (paste the OCID):
$ fn update context oracle.compartment-id <compartment-ocid>
Configure the newly created context with the api-url endpoint to use when using the Fn Project API:
$ fn update context api-url https://functions.us-phoenix-1.oraclecloud.com
Configure the context with the Docker Registry (Oracle private registry):
$ fn update context registry <region-code>.ocir.io/<tenancy-name>/<repo-name>
The tenancy name can be acquired from:
And the repo-name from here:
Configure the new context with the name of the profile you’ve created for use with Oracle Functions by entering:
$ fn update context oracle.profile <profile-name>
The profile-name is related with the OCI profile (I did not mention it previously, but you need to install and configure your OCI CLI https://docs.cloud.oracle.com/iaas/Content/API/SDKDocs/cliinstall.htm )
To get the profile, do this:
Before using the FN CLI, we need to create a token to be able to login to the docker registry, to do so:
Open the User menu and go to User Settings. On the Auth Tokens page, click Generate Token.
Enter a description and click Generate Token.
Copy the auth token and save it, since you will not see it again.
Then just do a:
$ docker login phx.ocir.io
from your prompt. Then, use the userid that you created to managed the compartment and for password, use the previously generated token.
Now you are ready to go with the FN CLI. Let’s create a first function, let’s use this example of text-to-speech (https://github.com/rcarrascosps/fn-text2speech). The steps are the following:
- Create the function using:
fn create app text2speech — annotation oracle.com/oci/subnetIds=’[“ocid1.subnet.oc1.phx.aaaaaaaazkk2knjfc7xf2ykctqzz5zjap6iryfbivkdeladwu2n64yuhdqsa”,”ocid1.subnet.oc1.phx.aaaaaaaaxnc7rolcl7d6r7ln5mjtkrllrzpag36qcguogvg7ilkfpowv24na”,”ocid1.subnet.oc1.phx.aaaaaaaat6zzt4cwxyubgavfhotflfltlns7o6rehnokunyjzl7mdnoyf36q”]’
You should see it here:
2 . Then deploy it with:
fn -v deploy --app text2speech
3. And finally invoke it with:
echo -n 'That was dope!' | fn invoke text2speech convert > op.wav && afplay op.wav
Open the op.wav and listen to it.
With that you have built and deployed your first function with Oracle Functions.