Leveraging OCI Functions to invoke OIC Integrations

Santhosh Kumar BVSRK
5 min readJun 29, 2022

--

Simple Architecture on calling OIC Integrations from OCI Functions

In today’s blog we’ll discuss on how to Leverage OCI Functions to invoke OIC Integrations.

Pre-Requisites

  1. Access to OCI Console.
  2. Access to OIC Instance and availability of Integrations to cover below scenarios.
  3. Access to create Function Applications & Functions within a compartment.
  4. Availability of a VCN & Subnet with a Function Application created.
  5. Availability of AuthToken for your user.

Assuming the above pre-requisites are met. We will discuss on how to call OIC Integrations from OCI Functions covering below scenarios.

Scenarios

a. Calling OIC Integration which doesn’t need any input Parameters → Calling an OIC EchoWorld Integration from OCI Functions.

b. Calling OIC Integration with a single Input & Output Parameter → Calling an OIC Hello World Integration from OCI Functions.

c. Calling OIC Integration with a single Input & Multiple Output parameters → Calling an OIC FetchEmpData Integration from OCI Functions.

d. Calling OIC Integration with multiple Input & Multiple Output parameters → Calling an OIC FetchEmpDeptData Integration from OCI Functions.

NOTE: To explain all these scenarios I am choosing Python as my language to build Functions. I will be building and invoking functions from OCI Cloud Shell in this blog. You can set it up on your local as well which ain’t scope of this blog.

How to create to the Fn environment and create a boiler plate function is given in detail in OCI Console.

Getting Started with OCI Functions

There are 3 parts to any function: (I) Creating (II) Deploying & (III) Invoking

Scenario (a) → Calling EchoWorld Integration (without Parameters)

Generating Boiler plate code

In this we’ll first generate a boiler plate code for function using the command

fn init — runtime python OICEchoWorld

These creates a function code with a directory OICEchoWorld in a chosen repo with 3 files (func.yaml, func.py & requirements.txt).

In the above snippet you are seeing an extra file InvokeEchoWorld.py, which we have created to invoke OIC Integration.

You might ask as to why can’t we write the entire code in a single .py file rather than separate files? We can very well do that, but I want to keep func.py as standard file which can be replicated across different other functions and keep another function specific to calling OIC Integration.

func.py

func.py
  1. Boiler plate creates a handler function which will where the incoming hit to your function land.
  2. Declaring logging i.e., level of logging and format of log i.e., with time followed by logging level (INFO) and the message to be printed in your log.
  3. declaring response variable to be returned
  4. storing data from input configuration variables in temp variables.
  5. Imported the integration related .py file, calling function/method inside that file along with parameters and storing output of that call in “resp” variable.

InvokeEchoWorld.py

InvokeEchoWorld.py
  1. storing username & password in a temp variable, to be passed to OIC call.
  2. sending GET method request to the Integration endpoint via oicbaseurl along with credentials.
  3. setting values to be returned in case of success. Sending “Message” field value from Integration output via ‘output’ field.

requirements.txt

requirements.txt

Need to add few more records here w.r.t OCI version and requests package which needs to be imported for calling OIC Integration.

func.yaml

func.yaml

This file basically gives your information as to name, version, runtime, memory etc., of your function.

Deploying Function

fn -v deploy — app <FunctionApplication>

Deploying Function to the application

Configuring Function Variables

Post deploying the function, in my case I am setting OIC Integration endpoint and credentials to make call.

Configuring Function Variables

Invoke Function

To invoke function you need to know the name of function, which can be obtained via the below command:

fn list functions <FunctionApplication>

List Functions in a Function Application

fn -v invoke <FunctionApplication> <FunctionName>

Invoke Function

Trigger in OIC

Trigger in OIC for EchoWorld

Scenario (b) → Calling HelloWorld Integration (with Single Input & Output Parameters)

Here I will be covering only the Integration specific .py file and how to invoke it. As rest of the part remains the same as in scenario (a).

InvokeHelloWorld.py

InvokeHelloWorld.py

Invoke Function

Here, I need to pass “Name” as Input to the Integration

Invoke Function

Trigger in OIC

Trigger in OIC for HelloWorld

Scenario (c) → Calling FetchEmpData Integration (with Single Input Parameter and multiple output parameters)

Here I will be covering only the Integration specific .py file and how to invoke it. As rest of the part remains the same as in scenario (a).

InvokeFetchEmpData.py

InvokeFetchEmpData.py

The only difference in InvokeFetchEmpData.py when compared to the previous files is the output variable.

Invoke Function

Here, I need to pass “EmpId” as Input to the Integration

Invoke Function

Trigger in OIC

Trigger in OIC for FetchEmpData

Scenario (d) → Calling FetchEmpDeptData Integration (with Multiple Input parameters and multiple output parameters)

Here I will be covering only the Integration specific .py file and how to invoke it. As rest of the part remains the same as in scenario (a).

InvokeFetchEmpDeptData.py

Invoke FetchEmpDeptData.py

Invoke Function

Here, I need to pass “EmpId” & “DeptNo” as Input to the Integration

Invoke Function

Trigger in OIC

!!! HAPPY READING!!!

Code for these is available in here → https://github.com/santhoshbvsrk/OCIFunctions

--

--

Santhosh Kumar BVSRK

17+ Years in IT/ITES| ML & AI Enthusiast| Oracle Cloud Architect, Integration Specialist — BPEL, OSB, OIC, IICS| Database Scripting-SQL, PL/SQL, MySQL