Oracle Cloud Infrastructure API Gateway and Oracle Functions

Rolando Carrasco
Dec 24, 2019 · 6 min read

Oracle Cloud Infrastructure API Gateway is a brand new component within the Developers Services in OCI.

We know that Oracle already had the Oracle API Platform Cloud Services which includes an API Gateway (Weblogic based); personally I’ve used it and deploy it for a couple of customers and is fine, it does the job. And if you are familiar with weblogic, then it was pretty straight forward to understand the architecture and deploy it. But when it comes to a serverless perspective, a modern type architecture, then we may have some trouble understanding that a big and fat Weblogic is sitting there as your gateway.

Oracle is moving in the right direction offering some pretty good things for developers within OCI. For example: Oracle Functions, Oracle Kubernetes Engine, Oracle Containers Registry; and now API Gateway.

API Gateway is a fully Oracle managed component, that is used to provide protected RESTful API endpoints for Oracle Functions, Oracle Kubernetes Engine, and other services on Oracle Cloud Infrastructure.

My favourite feature, so far, is its integration with Oracle Functions. I’ve been working with the Oracle Fn Project since December 2017, and last year that Oracle finally released Oracle Functions I confirmed that is a very good offering. Not only technology wise, but also for the credits consumption; it offers a very competitive price.

This article is about the integration between this new API Gateway and Oracle Functions. If you want to learn little bit about Functions before going directly with this article, take a look at this

Oracle Functions is a FaaS (Functions as a Service) serverless offering, that was released early this year (2019). You can create functions with different programming languages, such as: Java, Go, NodeJS, Python, etc. Functions are pretty well integrated with the authentication and authorization capabilities of OCI and the way you can call them is trough the fn CLI and through OCI events.

For example, a very simple helloworld function looks as follows:

We have an application by the name helloworld-app and a function call helloworld-func. In order to call it we use the fn CLI and the command invoke. The code of this function is pretty simple:

package com.example.fn;

public class HelloFunction {

public String handleRequest(String input) {
String name = (input == null || input.isEmpty()) ? “world” : input;
System.out.println(“Hello, “ + name + “!”);
return “Hello, “ + name + “!”;


Nothing strange with this, a very simple code, no annotations, nothing really proprietaty. Just a simple functions that receives an input and returns something. In this case Hello + your name.

But if you want to call it externally? Without the fn CLI, without the oci curl command? Then the API Gateway can be an option, it actually has a very cool integration with it.

To create an API Gateway is pretty straight forward, it just needs to create a couple of policies:

  • Allow group acme-apigw-developers to manage api-gateway-family in compartment acme-apigw-compartment
  • Allow group acme-apigw-developers to manage virtual-network-family in compartment acme-network

Before that you sould create a group (apigw-developers, for instance) and a compartment (apigw-compartment).

You should had also created a Virtual Cloud Network within this compartment (apigwc-compartment).

Here is a quick start for API Gateway that includes those steps:

Just follow it and you will have your API Gateway up and running with a first deployment.

And to allow the gateway to call functions you must create a couple of additional policies and a rule, you can find the documentation here:

In order to follow the next steps, you should had performed the steps included in the quick start. If you are done with that and you have already in place Oracle Functions then the next paragraphs should be interesting for you.

There are two ways to integrate Oracle Functions with API Gateway, both from the Web Console:

  1. Configuring all within the web console
  2. Create a JSON file that includes the details of the functions you want to integrate. Let’s use this one.

The first step is to create a JSON file like the following:

“routes”: [
“path”: “/helloworld”,
“methods”: [“GET”],
“backend”: {
“functionId”: “ocid1.fnfunc.oc1.iad. — afeaasfdafsasfasfsadf”

The elements are very self-explanatory:

a) path: is the path that we can to use to call the function

b) methods: is the list of methods you can to allow the API to receive

c) backend: in this case: ORACLE_FUNCTIONS_BACKEND and the function ID (OCID).

The entire list of elements and its descriptions can be found here:

Go to your OCI console and sign-in as an API Gateway Developer (a user that belongs to the group that I mentioned before).

Go the Menu and click on Developer Services:

Once you click on it, select the compartment where you create the VCN (previous steps):

In my case: apigtwycompartment.

In the quick start you should had already created your first acme-api-gateway. Click on it and you will be taken to the gateway main page:

Click on Deployments and you will be taken here:

Click on Create Deployment, and then click on the right side button:

Then put a name for your deployment and put a name for the path prefix. And in the option for Drop a file or select one (red square in the image), select the json file that we created in previous steps.

Once you have selected the file, click on the NEXT button:

The summary will appear, and then just click on CREATE:

After that the deployment will be created:

Wait until it says: Active and the circle is in green:

Now is time to call the function through the API.

First we need to get the address, in order to obtain it, get back to the API Gateway page:

Copy the hostname, and then issue a curl command like this:

curl -k -X GET

This is a very simple example, but it illustrates how easy is to integrate the brand new API Gateway with Oracle Functions.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade