This article is fairly rough log of the steps I went through to get going on Oracle Cloud Serverless Functions. It is mainly intended to provide a note to myself, for future reference. However, my description could prove useful to you – the reader.
My steps to get going are based on https://docs.cloud.oracle.com/iaas/Content/Functions/Tasks/functionscreatingfirst.htm. Another very useful resource with step by step descriptions: https://www.oracle.com/webfolder/technetwork/tutorials/infographics/oci_faas_gettingstarted_quickview/functions_quickview_top/functions_quickview/index.html.
Using a fresh OCI Cloud Tenancy and a local VM: Ubuntu 18.04 with Docker 19.03.5. In this VM, I run a Docker Container that contains the OCI CLI (as described in this article: https://technology.amis.nl/2018/10/14/get-going-quickly-with-command-line-interface-for-oracle-cloud-infrastructure-using-docker-container/) . A small configuration file lives outside the container and is mounted into the container contains tenancy details and the private key. This same file is used in the FN context that I use when deploying and invoking functions.
After deploying a function to the designated compartment in my OCI tenant, I will have the function’s container image in the Oracle Container Image Registry and the Function itself in the Application in the compartment.
Steps:
- Prepare the Oracle Cloud Infrastructure Command Line Interface for the designated OCI tenancy – https://technology.amis.nl/2018/10/14/get-going-quickly-with-command-line-interface-for-oracle-cloud-infrastructure-using-docker-container/ This article lists the following steps:
- create new OCI user functions-admin in group Admins – note down user and tenancy OCID, Region,
- prepare directory for OCI config file
- run OCI CLI Docker container image; this generates the oci config file and a private/public key-pair (outside the container)
- update OCI user in OCI browser console with public key
- create shortcut command for running OCI CLI on Docker host (in the .profile)
- Create OCI Compartment – functions-compartment
- Run OCI Networking Quickstart wizard – to create VCN, subnets, internet gateway, NAT gateway, service gateway
- Further Prepare Tenancy for Function Development – https://docs.cloud.oracle.com/iaas/Content/Functions/Tasks/functionsconfiguringtenancies.htm; we make use of a script that leverages the OCI CLI to prepare the tenancy: https://github.com/lucasjellema/oci-scripts/tree/master/functions. The script performs these steps for us:
- create group
- create policies
- create Application
run the script with tenancy OCID as command line parameter
- Install/Configure oci-curl: https://docs.cloud.oracle.com/iaas/Content/Functions/Tasks/functionscreatinglocalocicurl.htm
- Install Project Fn CLI on the Linux Host – https://docs.cloud.oracle.com/iaas/Content/Functions/Tasks/functionsinstallfncli.htm
- Configure Project Fn context – https://docs.cloud.oracle.com/iaas/Content/Functions/Tasks/functionscreatefncontext.htm
- Set the Context for the Fn Project CLI Using the oracle.profile Parameter – https://docs.cloud.oracle.com/iaas/Content/Functions/Tasks/functionssetoracleprofile.htm
- fn update context oracle.profile FN
- Generate an Auth Token to Enable Login to Oracle Cloud Infrastructure Registry – https://docs.cloud.oracle.com/iaas/Content/Functions/Tasks/functionsgenerateauthtokens.htm
- Login to Docker
- docker login <region-code>.ocir.io (in my case docker login iad.ocir.io)
- username: tenancy-namespace/user (where <tenancy-namespace> is the auto-generated Object Storage namespace string of the tenancy in which to create repositories (as shown on the Tenancy Information page) and password is the generated Auth Token.
- Verify configuration – https://docs.cloud.oracle.com/iaas/Content/Functions/Tasks/functionsverifyingconfig.htm
- Create a new Hello World Function on the command line and deploy it – Steps 5 through 10 in https://docs.cloud.oracle.com/iaas/Content/Functions/Tasks/functionscreatingfirst.htm
-
Invoke the new Function in one of several ways: (see https://docs.cloud.oracle.com/iaas/Content/Functions/Tasks/functionsinvokingfunctions.htm)
-
fn invoke lab-app hello
-
oci fn function invoke –function-id ocid1.fnfunc.oc1.iad.aa4q –file “-” –body ‘{“param1”: “value1”}’
-
through API Gateway
-
from application program using OCI Client SDK
-
oci raw-request –http-method POST –target-uri https://se3z5wq.us-ashburn-1.functions.oci.oraclecloud.com/20181201/functions/ocid1.fnfunc.oc1.iad.aaaaaa4q/actions/invoke –request-body “”
- oci-url
- fn inspect function lab-app hello => this returns the function endpoint
fn create context lab-fn-context –provider oracle
fn use context lab-fn-context
fn update context oracle.compartment-id <compartment-ocid>
fn update context api-url https://functions.us-ashburn-1.oci.oraclecloud.com
fn update context registry iad.ocir.io/idtxxxxanz/cloudlab-repo
source ~/oci-curl/oci-curl.sh
oci-curl “se3lwq.us-ashburn-1.functions.oci.oraclecloud.com” post payload.json “/20181201/functions/ocid1.fnfunc.oc1.iad.aaq/actions/invoke”
Here end the first steps: the first function is running and can be invoked. Next steps include creating more exciting functions, exposing functions through the API Gateway, calling functions from Oracle Integration Cloud integrations and scheduling function execution (for now using either OKE CronJob or with IFTTT and API Gateway.
Resources
Oracle Functions – Quick Start Guide: https://www.oracle.com/webfolder/technetwork/tutorials/infographics/oci_faas_gettingstarted_quickview/functions_quickview_top/functions_quickview/index.html
Running OCI CLI in Docker Container (to keep the development environment ‘clean’): https://technology.amis.nl/2018/10/14/get-going-quickly-with-command-line-interface-for-oracle-cloud-infrastructure-using-docker-container/