Functions: Get Started using Cloud Shell
In this tutorial, you use an Oracle Cloud Infrastructure account to set up Oracle Functions development using Cloud Shell. Then, you create a function application and a function.
Key tasks include how to:
- Set up an authentication token.
- Gather required information.
- Set up a VCN.
- Log in to OCI Registry (OCIR).
- Configure Cloud Shell to deploy functions.
- Configure your Fn context.
- Create an app for your Oracle function.
- Create a function.
- Deploy your function.
- Test your function.
For additional information, see:
Before You Begin
To successfully perform this tutorial, you must have the following:
- A paid Oracle Cloud Infrastructure account. See Signing Up for Oracle Cloud Infrastructure.
- Your OCI account configured to support Oracle Functions development. See Oracle Functions on Cloud Shell Quickstart.
- OCI Cloud Shell which is included with your account and includes:
- OCI CLI
- Docker
- Python 3.6+
- Java 1.8+
- Node.js 10+
1. Gather Required Information
Collect all the information needed to complete the tutorial.
Prepare the information you need from the OCI Console.
- Find your region identifier and region key from Regions and Availability Domains.
Example:
us-ashburn-1
andiad
for Ashburn. - Create a registry project name to store your function images in OCI Registry
(OCIR).
When you publish a function, a Docker image is created in OCIR. Your OCIR project name is prepended to your function images to make them easy to find. For example, given:
- Registry project name:
my-func-prj
- Function name:
node-func
Your function image would be stored on OCIR under:
my-func-prj/node-func
- Registry project name:
To create a compartment see Create a compartment. After your compartment is created, save the compartment OCID.
To get the compartment OCID from an existing compartment:
- Open the navigation menu and click Identity & Security. Under Identity, click Compartments.
- Select your compartment.
- Click the Copy link for the OCID field.
You create an authorization token to log in to the OCI Registry. To create an authorization token:
Collect all the information needed to complete the tutorial. Copy the following information into your notepad.
2. Create your Virtual Cloud Network (VCN)
Set up a VCN to connect your Linux instance to the internet.
To configure virtual cloud network, perform the following steps.
To open a different port, replace 80 in the last step with the port number.
3. Log into the OCI Registry
Next, you log Docker into the OCI Registry (OCIR).
- Get the information you gathered earlier.
- Open a terminal window.
- Log in to OCIR:
docker login <region-key>.ocir.io
You are prompted for your login name and password.
- Username:
<tenancy-name>/<user-name>
- Password:
<auth-token>
- Username:
You have logged your instance into OCIR.
4. Configure Functions
To use Oracle Functions, you must configure the Fn application context. The context stores the values needed to connect to the Oracle Functions service. Fn client commands are used to add the required configuration data.
You need the information you gathered from earlier on. Use Fn client commands to configure Fn.
View/Edit your Context
Your Fn context files are in the ~/.fn/contexts
directory. Each context is stored in a .yaml
file. For example,
your us-phoenix-1.yaml
file might look similar to:
api-url: https://functions.us-phoenix-1.oci.oraclecloud.com
oracle.compartment-id: ocid1.compartment.oc1..aaaaaaaarvdfa72n...
provider: oraclecs
registry: phx.ocir.io/my-tenancy/my-func-prj
You can edit the file directly with an editor if necessary.
For a detailed explanation of each step, see: Oracle Functions on Cloud Shell Quickstart
You have now setup the Fn context for your instance.
5. Create and Deploy a Function
With your configuration complete, create and deploy a function.
An Application is the main storage container for functions. Each function must have an application for deployment. To create application, follow these steps.
- Open the navigation menu and click Developer Services. Under Functions, click Applications.
- Click Create Application.
Fill in the form data.
- Name: <your-app-name>
- VCN: <your-VCN>
- Subnets: <your-public-subnet> or <your-private-subnet>
Note
A public or private subnet can be used, select one. - Click Create.
Your app is created.
Choose a Language
Select one of the following languages to create and deploy a function. If you want, you can do all three.
With your application created, deploy a Java function. Follow these steps to create a Java "Hello World" function.
Ensure Java 8+ is installed to perform these steps.
You have successfully deployed and tested a Java function.
With your application created, deploy a Python function. Follow these steps to create a Python "Hello World" function.
You have successfully deployed and tested a Python function.
With your application created, deploy a Node function. Follow these steps to create a Node "Hello World" function.
Ensure Node.js 10+ is installed to perform these steps.
You have successfully deployed and tested a Node function.
6. Review Function Information
After your functions run, information about your functions is available in the OCI Console.
When you deploy, the function is uploaded and stored in OCIR. You can navigate to OCIR and examine the function images.
- Open the navigation menu and click Developer Services. Under Containers & Artifacts, click Container Registry.
- Search for the
<your-repository-project-name>
. - Under your project name, you see an entry for each function you deployed.
- Click the link of each image you want to see information about.
After you run a function, you can display metrics for that function.
- Open the navigation menu and click Developer Services. Under Functions, click Applications. Your applications are listed on the page.
- Click the link to the application you created.
- Click the link to the function you want to examine.
Metric information about your function is displayed.
To enable logging for an application, follow these steps.
- Open the navigation menu and click Developer Services. Under Functions, click Applications. Your applications are listed on the page.
- Click the link to the application you created.
- On the left side of the application page, click the Logs link.
- Click Disabled to enable logging for your application.
- The Enable Log dialog is displayed. Fill in the following information:
- Compartment: <your-compartment-name>
- Log Group: Take the default value
Auto-Create a Default Log Group
- Log name:
<take-default>
- Log Retention:
<take-default>
- Click Enable Log
Wait a moment for your log to be created.
To view your log, click the log name link created by the preceding steps.
What's Next
You have successfully created a function and deployed it to Oracle Functions.
To explore more information about development with Oracle products, check out these sites: