Difficulty: beginner
Estimated Time: 30 minutes

This scenario introduces the OCI Application Gateway. It is used to provide access to a Stock Response and to HTTP Backends. It is also used to expose serverless Functions on Oracle Cloud Infrastructure through a public endpoint. It was prepared for the Meetup Workshop Cloud Native application development on Oracle Cloud Infrastructure in January 2020, hosted by AMIS|Conclusion in Nieuwegein in collaboration with REAL (the Red Expert Alliance) and Link from Portugal. It was updated for the REAL OCI Handson Webinar Series that started in June 2020.

You will use the OCI Console to verify the creation of API Deployment with Routes and to monitor the calls to API Gateway. You can inspect the logging from the API Deployment on Object Storage - although it will take some time for the logging to arrive in the OCI Object Storage Bucket.

The scenario uses an Ubuntu 19.04 environment with Docker and OCI CLI. Before you can start the steps in the scenario, the OCI Command Line interface is downloaded and installed for you. This will take about one minute. You will need Postman as well, if you want to invoke the routes on API Gateway directly from your computer.

The scenario expects a number of preparations:

  • you already have deployed a function called hello# in an application called lab# where # is a number (either 1 or a number assigned to you in a workshop); the function app and function are in an OCI compartment lab-compartment. (this is part of the Functions on OCI scenario)
  • an API Gateway already has been provided in compartment lab-compartment with permissions to access functions in this compartment; the API Gateway is associated with a public subnet (this is part of the OCI Tenancy Preparation Scenario)

Note: it is assumed that you prepared an OCI tenancy using the Katacoda scenario Preparation of Cloud Trial tenancy for REAL OCI scenarios. This preparation will have created the VCN you need for running functions in OCI as well as the lab-compartment in which the functions are created. Additionally, you should have created a key pair in this scenario and prepared the contents of the config and oci_api_key.pem files. If you have not gone through this OCI tenancy preparation, please do so before continuing with this scenario. You also need an Auth Token to login to the OCIR Container Registry; this too is created in the preparation scenario and used in the Function on OCI scenario.

Overview of Function running on Fn

REAL - Red Expert Alliance


This completes your explorations with the OCI API Gateway. The next scenario you may want to explore looks at more complex Functions on OCI - functions that invoke other functions and other OCI services such as Object Storage.

Background Resources

Introducing Oracle Cloud API Gateway – the light weight public or private router to public and private OCI endpoints – https://technology.amis.nl/2019/12/23/first-steps-with-oracle-cloud-api-gateway-the-light-weight-public-or-private-router-to-public-and-private-oci-endpoints/

First steps with API Gateway – https://technology.amis.nl/2019/12/23/my-first-steps-with-oracle-cloud-api-gateway-the-stock-response/

OCI API Gateway Docs – Adding a Function in Oracle Functions as an API Gateway Back End – https://docs.cloud.oracle.com/iaas/Content/APIGateway/Tasks/apigatewayusingfunctionsbackend.htm

Article/Tutorial by Todd Sharp – Creating Your First API Gateway In The Oracle Cloud – https://blogs.oracle.com/developers/creating-your-first-api-gateway-in-the-oracle-cloud

API Gateway on Oracle Cloud Infrastructure

Step 1 of 4

Step 1 - Prepare Fn and OCI CLI

Wait for OCI CLI and Fn CLI to be installed

You need to provide details on the OCI tenancy you will work in and the OCI user you will work as. Please edit these two files:

  • ~/.oci/config
  • ~/.oci/oci_api_key.pem

Paste the contents that you prepared in the OCI Tenancy preparation scenario.

Set the environment variable LAB_ID to 1 - unless you are in a workshop with multiple participants and each uses their own number.

export LAB_ID=1

Note: in order to ensure that all workshop participants will have their own individual copies of the function (and more specifically: of the Function's container image on OCI Container Registry), we need to add the participant's LAB_ID to the name of the function.

Do not continue until you see the file /root/allSetInBackground appear. If it appears, then the OCI CLI has been installed and you can continue.

Try out the following command to get a list of all namespaces you currently have access to - based on the OCI Configuration defined above.

oci os ns get

If you get a proper response, the OCI is configured correctly and you can proceed. If you run into an error, ask for help from your instructor.

Now please set the Region environment variable using this command:

export REGION=$(oci iam region-subscription list | jq -r '.data[0]."region-name"')
export REGION_KEY=$(oci iam region-subscription list | jq -r '.data[0]."region-key"')
export USER_OCID=$(oci iam user list --all | jq -r  '.data |sort_by(."time-created")| .[0]."id"')

Environment Preparation

Prepare a number of environment variables. Note: the assumptions here are a compartment called lab-compartment and an API Gateway lab-apigw in that same compartment. We need to get references to these resources in order to create new resources in the right place.

cs=$(oci iam compartment list)
export compartmentId=$(echo $cs | jq -r --arg display_name "lab-compartment" '.data | map(select(."name" == $display_name)) | .[0] | .id')

apigws=$(oci api-gateway gateway list -c $compartmentId)
export apiGatewayId=$(echo $apigws | jq -r --arg display_name "lab-apigw" '.data.items | map(select(."display-name" == $display_name)) | .[0] | .id')

And now we are finally ready to create an API Deployment on API Gateway on Oracle Cloud Infrastructure. But let's first inspect the API Gateway that was created in the OCI Tenancy Preparation Scenario.

Open the Console to Developer Services | API Gateway and navigate to the API Gateway lab-apigw.

echo "open the console at https://console.$REGION.oraclecloud.com/api-gateway/gateways/$apiGatewayId"