Contributing Author: Sachin Pikle, Product Strategy Director
Today, we’re excited to announce two additions to Oracle Functions:
What if you could deploy and test functions without installing and configuring Docker, the Fn CLI, and the Oracle Cloud Infrastructure (OCI) CLI, while ensuring that you follow Oracle Cloud Infrastructure security best practices? This is now possible with Cloud Shell.
Cloud Shell gives you access to an always available Linux shell directly in the Console. It contains Docker, a preauthenticated Fn CLI, and OCI CLI. With Cloud Shell, you can quickly deploy and test functions entirely from your web browser. You don’t have to install anything.
To make it easier for new users, we have added a Getting Started Cloud Shell Setup tab to the Application details screen in the Console. This tab contains ready-to-run instructions that you can simply copy and paste in Cloud Shell.
Let’s go through the steps to run a simple Hello World function. Let’s assume that you have the right IAM policies in place and that you have created an application in Oracle Functions. If not, refer to the Oracle Functions Quick Start Guide for Cloud Shell.
From the main menu in the Console, select Developer Services, and then select Functions.
Click your application, and under Getting Started, click Cloud Shell Setup.
Click Launch Cloud Shell.
Check and confirm that the Fn CLI is set up to use the context for your region (for example, us-ashburn-1).
$ fn inspect ctx
$ fn use context us-ashburn-1
Update the function's compartment ID and the Oracle Cloud Infrastructure Registry location where you will push images.
$ fn update context oracle.compartment-id [YOUR COMPARTMENT OCID]
$ fn update context registry iad.ocir.io/[YOUR TENANCY NAMESPACE]/[YOUR OCIR REPO]
Create an auth token that you will use to authenticate to the registry: Click Generate an AuthToken. Under Resources, click Auth Tokens and then click Generate Token. Provide a description for your token and copy its value.
Log in to Registry. When prompted for a password, enter the auth token that you just generated.
$ docker login -u '[YOUR TENANCY NAMESPACE]/[YOUR USERNAME]' iad.ocir.io
You’re ready to deploy functions. Let's create a Hello World function.
Generate the boilerplate Python function.
$ fn init --runtime python hello-python
Go to the hello-python folder.
$ cd hello-python
Deploy the function.
$ fn -v deploy --app banking-app
Invoke the function.
$ fn invoke banking-app hello-python
The message {"message": "Hello World"} should be displayed.
Congratulations! You’ve successfully deployed and tested a function with Cloud Shell.
In discussions with customers, we see a many common serverless patterns and use cases with functions. Chances are that your use case is similar in nature and that you can benefit from such implementations. To get you started, we’re creating a collection of how-to's, patterns, use cases, and other samples available to you in the Oracle Functions Samples repository on GitHub.
The repo contains examples of how to interact with other Oracle Cloud Infrastructure services, how to optimally connect to databases, how to use Events to trigger functions, and more. It also contains concrete use cases for IT Governance, Data Processing, SaaS Application Extensions, and more. We’ll continue to publish additional samples, so bookmark this repo!
Here is a classic use case. You extract data from various databases and applications. You need to import this data automatically into Oracle Autonomous Data Warehouse to analyze it. In the process, the data might need to be cleaned up. To implement this process, the data is programmatically uploaded into an Object Storage bucket. This action emits a new event that triggers a function that takes the data, processes it, and loads it into Autonomous Data Warehouse. After the data is processed, it’s moved to a different bucket for reconciliation.
The code for the function is available in the repo in the oci-load-file-into-adw-python folder.
Each folder in the repo contains a sample. Each sample comes with the function code and a README file that describes which IAM policy to set, and how to deploy and configure the function.
Let’s use Cloud Shell to deploy the oci-list-instances-java sample.
In the Console, create a dynamic group for your function: In the main menu, select Identity, and then select Dynamic Groups. Click Create Dynamic Group, and enter a name and a matching rule that matches all functions in your compartment. For example:
ALL{resource.type='fnfunc', resource.compartment.id='ocid1.compartment.oc1..aaaaaxxxxxx'}
Create an IAM policy to allow your dynamic group to list compute instances: In the main menu, select Identity, and then select Policies. Click Create Policy, and enter a name and the following policy statement:
Allow dynamic-group mydg to inspect instances in compartment mycompartment
In this example, mydg is the name of your dynamic group, and mycompartment is the name of your compartment
Launch Cloud Shell.
Check your Fn context to ensure that your region, compartment, and registry are correct.
$ fn inspect ctx
Clone the sample repository.
$ git clone https://github.com/oracle/oracle-functions-samples
Change the directory to the oci-list-instances-java sample.
$ cd oracle-functions-samples/oci-list-instances-java
Reusing the application we already created, deploy the function.
$ fn deploy --app banking-app
Test the function by providing your compartment OCID to the fn invoke command.
$ echo -n 'ocid1.compartment.oc1..aaaaaxxxxxx'| fn invoke banking-app oci-list-instances-java
The function should return the list of instances in your compartment.
Oracle Functions quick start guide, documentation, and FAQ
Oracle Functions samples repo
Oracle Cloud Shell documentation
Oracle Cloud account free trial