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. The it is also used to expose serverless Functions on Oracle Cloud Infrastructure through a public endpoint. The scenario was prepared for the Meetup Workshop Cloud Native application development on Oracle Cloud Infrastructure on January 20th, hosted by AMIS|Conclusion in Nieuwegein in collaboration with REAL (the Red Expert Alliance) and Link from Portugal.

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 18.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. 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 assigned to you (in OCI compartment lab-compartment)
  • 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

You will need several pieces of information from the workshop instructor:

  • your lab participant number
  • contents for OCI Config File
  • private key to go with the OCI Config File
  • username and password to login to OCI Console

Make sure you get those.

Overview of Function running on Fn

AMIS | Conclusion

Summary

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 provided by the workshop instructor into these two files.

Set the environment variable LAB_ID to the number provided to you by the workshop instructor.

export LAB_ID=1

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.

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.