X

The Visual Builder Cloud Service Blog

Connecting to Oracle Functions from Visual Builder

Aparna Gaonkar
Product Manager

Oracle Functions, the serverless offering from Oracle Cloud Infrastructure is an excellent way to run your code without worrying about the underlying infrastructure, and also helps to optimize your costs as you only pay per invocation of the Function.

In the previous blog, we connected to an OCI REST API using the OCI Signature authentication.  In this blog we go a step further and invoke a simple Hello World OCI Function from a VB application

Setting up the OCI Function

Login to the OCI console for your tenancy.  Make sure the user that you are logging with has the relevant permissions to create Functions, VCNs, repositories etc. via IAM Policies (This can be accomplished using groups and policies ).  In my case I am logging via a user who is in the OCI Administrators group which has access to manage all resources.  
 
Tip : Within the OCI console, you can click the Hamburger menu and navigate through various offerings, or you could use the search to quickly get to the thing you are interested in.

Create a Compartment

First, we will create a Compartment where our Function and related resources will live.  A Compartment can be thought of a logical grouping of OCI resources, to which you can grant access to various users (or other principals).  

We navigate to the Compartment via search or via the hamburger menu ( Identity -> Compartments ).  Here we will create a new compartment called oci-fn-vb - this will be the place where we will create all our OCI resources.  Note down the OCID of the compartment for future use.


Create a Virtual Cloud Network (VCN)

A VCN is necessary for the Function to communicate with the outside world.  Navigate to Virtual Cloud Networks via search or via the hamburger menu (Networking -> Virtual Cloud Networks).  You can choose the "Start VCN Wizard" for quickly creating the right configuration of VCNs that also has Internet Connectivity.  Uncheck the "Use the DNS Hostnames" option and let all the other values remain default (Note - the wizard also creates a private subnet and a NAT gateway, that we wont be using in this tutorial)

 

Here is how the VCN looks after the creation. We will be creating our Function resources in the public Subnet of this VCN.


Create a repository

OCI Functions are stored as Docker Images and hence need a Docker repository to be created within the OCI Registry (OCIR).  To create a new repository you can go to Developer Services -> Registry and create a new repository and note its name.  In this tutorial, I use a repository called oci-fn-repository

This repository would be used when using the Quick Start for the function.

Create an Application for the Function 

We will first create an Application to add the function to.  Navigate to Developer Services -> Functions from the hamburger menu (or use the quick search).  Proceed to create an Application choosing the oci-fn-vb compartment (for both the VCN and the subnet) and keep the other stuff default.  The Application in my case is called oci-fn-vb-app


 

Create the hello-java Function

Now open the newly created oci-fn-vb-app and click on the Getting started link available.  This will guide you through all the steps of creating a helloworld boilerplate java function via the OCI Cloud Shell and deploying it.  You would be using the repository already created to push the function image to.  At the last step you should be able to invoke hello-java function successfully from CloudShell.

Tip : There are other Quick start samples for Oracle Functions on GitHub.  You can follow the instructions in the given README to install these Functions

If we now check the OCI console for oci-fn-vb-app (remember to select the compartment you created it in) and navigate to Functions, we can now see the deployed hello-java Function

Note down the Invoke endpoint of the hello-java function, as this is what we will be using to call the Function from VB.  It will be of the following format

https://7imgabcd.ap-mumbai-1.functions.oci.oraclecloud.com/20181201/functions/ocid1.fnfunc.oc1.ap-mumbai-1.aaaaaaaaaby.xsysd....zxs5qq/actions/invoke

 

Obtaining the Credentials from OCI

We have already covered this part in the "Getting OCI Credentials section" of the previous blog about OCI Signature authentication. Basically we need a key ID and a unencrypted private key to use in VB.

Setting up the Service Connection in VB to call hello-java Function

Create the Service Connection

Login to Visual Builder.  Create a Visual Application OCIFunctionTest .  In this, navigate to Service Connections and proceed to create a Service Connection.  Choose the Define by Endpoint category when prompted to select Source

In the Service Connection Wizard, choose as below :


Method : POST
URL : the Function invoke endpoint that we copied earlier (e.g. https://7imgabcd.ap-mumbai-1.functions.oci.oraclecloud.com/20181201/functions/ocid1.fnfunc.oc1.ap-mumbai-1.aaaaaaaaaby.xsysd....zxs5qq/actions/invoke)
Action Hint : Create

 

In the next screen, the service name/id has been automatically populated.  Change this to be a meaningful value.  In my example the service is called ociFunction

Add key ID and private key to the Service Connection Credentials

Navigate to the Server tab to specify the authentication details.  

Choose Authentication to be Oracle Cloud Infrastructure API Signature 1.0.  This is the API Signatures algorithm mentioned here.  Note that the Service Connection will always go via the proxy irrespective of what is chosen in the Connection Type attribute, due to the nature of the OCI Signature authentication.

Click on the pencil icon next to the API Key.  There would be a place holder to put in the API Key as well as the Private Key.  Use the entire part of the Private Key including the BEGIN PRIVATE KEY till END PRIVATE KEY.  Save the credentials.

 

Add the request body

In this case the hello-java accepts text/plain mime type, change the Media Type to be "text/plain", and give a sample request text.  

Test and create the Service Connection

After this, test the endpoint connectivity by navigating to the Test Tab.  Change the request type to text/plain and give a sample request text if not already so.  Click Send to obtain the response.  You should get a 200 OK response with the output of the Function as below.  

Finally, create the Service Connection.

That completes the setup of service connection from VB to an OCI Function.  You can now wire up this newly created Service Connection to webapps or mobile apps.

 

 

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.