X

The latest cloud infrastructure announcements, technical solutions, and enterprise cloud insights.

Oracle Functions: Announcing Samples Repository and Quick Start with Cloud Shell

Greg Verstraeten
Senior Principal Product Manager

Contributing Author: Sachin Pikle, Product Strategy Director

Today, we’re excited to announce two additions to Oracle Functions:

  • Quickly deploy and test functions from Cloud Shell: We’ve integrated Oracle Functions with Oracle Cloud Shell and added a Cloud Shell Getting Started section in the Oracle Cloud Infrastructure Console. Now you can deploy, configure, and test your functions within minutes, entirely from the Console by using Cloud Shell.
  • Oracle Functions Samples repository: We’ve published a collection of sample functions on GitHub to show you how to use Functions to implement common serverless patterns and use cases. With these samples, you can quickly learn, adapt, and build your own functions.

Quickly Deploy and Test Functions from Cloud Shell

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.

Screenshot that shows the details page for an application in the Oracle Cloud Infrastructure Console. In the Getting Started section, the Cloud Shell Setup tab is selected, and the steps for creating a functions in Cloud Shell are displayed.

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.

  1. From the main menu in the Console, select Developer Services, and then select Functions.

  2. Click your application, and under Getting Started, click Cloud Shell Setup.

  3. Click Launch Cloud Shell.

    Screenshot that shows the Launch Cloud Shell button.

  4. 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
  5. 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]
  6. 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.

    Screenshot that shows the Generate an AuthToken link.

  7. 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.

  8. Generate the boilerplate Python function.

    $ fn init --runtime python hello-python

    Screenshot that shows the Cloud Shell window open at the bottom of the application details page.

  9. Go to the hello-python folder.

    $ cd hello-python 
  10. Deploy the function.

    $ fn -v deploy --app banking-app
  11. 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.

Functions Samples on GitHub

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.

Diagram that shows the described process. Users drop CSV files into an Object Storage bucket, Object Storage emits events, Cloud Events triggers a function, the function extracts and loads the data into Autonomous Data Warehouse. The file is moved to the processed bucket.

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.

Quickly Run a Sample Function in Cloud Shell

Let’s use Cloud Shell to deploy the oci-list-instances-java sample.

  1. 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'} 
  2. 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

  3. Launch Cloud Shell.

  4. Check your Fn context to ensure that your region, compartment, and registry are correct.

    $ fn inspect ctx
  5. Clone the sample repository.

    $ git clone https://github.com/oracle/oracle-functions-samples
  6. Change the directory to the oci-list-instances-java sample.

    $ cd oracle-functions-samples/oci-list-instances-java
  7. Reusing the application we already created, deploy the function.

    $ fn deploy --app banking-app
  8. 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.

More Information

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha