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.
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
To configure virtual cloud network, perform the following steps.
Click the Oracle Cloud icon to go to the main landing
page.
Scroll down to Launch Resources.
Select Set up a network with a wizard.
In the Start VCN Wizard workflow, select Create VCN with Internet
Connectivity and then click Start VCN Wizard .
In the configuration dialog, fill in the VCN Name for your VCN. Your
Compartment is already set to the last compartment you were working in, or if
it's your first time, to its default value of <your-tenancy>
(root).
In the Configure VCN and Subnets section, keep the default values for
the CIDR blocks:
VCN CIDR BLOCK: 10.0.0.0/16
PUBLIC SUBNET CIDR BLOCK: 10.0.0.0/24
PRIVATE SUBNET CIDR BLOCK: 10.0.1.0/24
Note
Notice the public and private subnets have different network
addresses.
For DNS Resolution, uncheck Use DNS hostnames in this VCN.
Click Next.
The Create a VCN with Internet Connectivity configuration dialog is
displayed (not shown here) confirming all the values you just entered.
Click Create to create your VCN.
The Creating Resources dialog is displayed (not shown here) showing
all VCN components being created.
Click View Virtual Cloud Network to view your new VCN.
Your new VCN is displayed. Now you need to add a security rule to allow HTTP
connections on port 80, the default port for your applications.
With your new VCN displayed, click your Public subnet link.
The public subnet information is displayed with the Security Lists at the
bottom of the page. There should be a link to the Default Security
List for your VCN.
Click the Default Security List link.
The default Ingress Rules for your VCN are displayed.
Click Add Ingress Rules.
An Add Ingress Rules dialog is displayed.
Fill in the ingress rule with the following information. Once all the data is
entered, click Add Ingress Rules.
Fill in the ingress rule as follows:
Stateless: Checked
Source Type: CIDR
Source CIDR: 0.0.0.0/0
IP Protocol: TCP
Source Port Range: (leave-blank)
Destination Port Range: 80
Description: VCN for applications
Once you click Add Ingress Rules, HTTP connections are allowed to your
public subnet.
Note
To open a different port, replace 80 in the last step with the port
number.
You have successfully created a VCN that makes your applications
available from the internet.
3. Log into the OCI Registry 🔗
Next, you log Docker into the OCI Registry (OCIR).
You are prompted for your login name and password.
Username:<tenancy-name>/<user-name>
Password:<auth-token>
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.
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:
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.
If you want to connect to your function from the net, you need to get the
function's invoke endpoint. To find your invoke endpoint use the
inspect command.
Copy
fn inspect function your-app-name my-func-name
Examine the results of the inspect command. Notice the invoke
endpoint URL is included in the annotatins section of the
returned JSON data.
Copy
{
"annotations": {
"fnproject.io/fn/invokeEndpoint": "https://aaaaaaaaa.us-ashburn-1.functions.oci.oraclecloud.com/1111111/functions/ocid1.fnfunc.oc1.iad.aaaaaaaaa.../actions/invoke",
"oracle.com/oci/compartmentId": "ocid1.compartment.oc1..aaaaaaaa...",
"__comment":"Remaining output left out for brevity",
Use the URL returned from inspect to invoke the function.
Because functions require requests to be digitally signed, the oci
raw-request command is used for this example.
oci raw-request --http-method POST --request-body "" --target-uri https://https://aaaaaaaaa.us-ashburn-1.functions.oci.oraclecloud.com/1111111/functions/ocid1.fnfunc.oc1.iad.aaaaaaaaa.../actions/invoke
If you want to connect to your function from the net, you need to get the
function's invoke endpoint. To find your invoke endpoint use the
inspect command.
Copy
fn inspect function your-app-name my-func-name
Examine the results of the inspect command. Notice the invoke
endpoint URL is included in the annotatins section of the
returned JSON data.
Copy
{
"annotations": {
"fnproject.io/fn/invokeEndpoint": "https://aaaaaaaaa.us-ashburn-1.functions.oci.oraclecloud.com/1111111/functions/ocid1.fnfunc.oc1.iad.aaaaaaaaa.../actions/invoke",
"oracle.com/oci/compartmentId": "ocid1.compartment.oc1..aaaaaaaa...",
"__comment":"Remaining output left out for brevity",
Use the URL returned from inspect to invoke the function.
Because functions require requests to be digitally signed, the oci
raw-request command is used for this example.
oci raw-request --http-method POST --request-body "" --target-uri https://https://aaaaaaaaa.us-ashburn-1.functions.oci.oraclecloud.com/1111111/functions/ocid1.fnfunc.oc1.iad.aaaaaaaaa.../actions/invoke
If you want to connect to your function from the net, you need to get the
function's invoke endpoint. To find your invoke endpoint use the
inspect command.
Copy
fn inspect function your-app-name my-func-name
Examine the results of the inspect command. Notice the invoke
endpoint URL is included in the annotatins section of the
returned JSON data.
Copy
{
"annotations": {
"fnproject.io/fn/invokeEndpoint": "https://aaaaaaaaa.us-ashburn-1.functions.oci.oraclecloud.com/1111111/functions/ocid1.fnfunc.oc1.iad.aaaaaaaaa.../actions/invoke",
"oracle.com/oci/compartmentId": "ocid1.compartment.oc1..aaaaaaaa...",
"__comment":"Remaining output left out for brevity",
Use the URL returned from inspect to invoke the function.
Because functions require requests to be digitally signed, the oci
raw-request command is used for this example.
oci raw-request --http-method POST --request-body "" --target-uri https://https://aaaaaaaaa.us-ashburn-1.functions.oci.oraclecloud.com/1111111/functions/ocid1.fnfunc.oc1.iad.aaaaaaaaa.../actions/invoke