6. Create an Fn Project CLI Context to Connect to Oracle Cloud Infrastructure
Before using Oracle Functions, you have to configure the Fn Project CLI to connect to your Oracle Cloud Infrastructure tenancy.
When the Fn Project CLI is initially installed, it's configured for a local development 'context'. To configure Fn Project CLI to connect to your Oracle Cloud Infrastructure tenancy instead, you have to create a new context. The context specifies Oracle Functions endpoints, the OCID of the compartment to which deployed functions will belong, and the address of the Docker registry to and from which to push and pull images.
You can define multiple contexts, each stored in a different context file in .yaml format. By default, the individual context files are stored in the
~/.fn/contexts directory. The
~/.fn/config.yaml file specifies which context file Fn Project uses.
To create a new context, you can create a new context file manually and edit the
~/.fn/config.yaml file by hand to point to that file. Alternatively, you can use the Fn Project CLI to interactively create the new context file and instruct the Fn Project CLI to start using that file, as described below.
The instructions in this topic assume you have already completed the steps in 5. Install the Fn Project CLI.
To create a new context file using the Fn Project CLI:
Log in to your development environment as a functions developer.
In a terminal window, create the new Fn Project CLI context for Oracle Cloud Infrastructure by entering:
$ fn create context <my-context> --provider oracle
where <my-context> is a name of your choosing. For example:
$ fn create context johns-oci-context --provider oracle
Specify that the Fn Project CLI is to use the new context by entering:
$ fn use context <my-context>
where <my-context> is the name you specified in the previous step. For example:
$ fn use context johns-oci-context
Configure the new context with the OCID of the compartment that you want to own the deployed functions (you might have created a new compartment specifically for this purpose, see Create Compartments to Own Network Resources and Oracle Functions Resources in the Tenancy, if they don't exist already) by entering:
$ fn update context oracle.compartment-id <compartment-ocid>
$ fn update context oracle.compartment-id ocid1.compartment.oc1..aaaaaaaarvdfa72n...
Configure the new context with the api-url endpoint to use when calling the API by entering:
$ fn update context api-url <api-endpoint>
<api-endpoint> is one of the endpoints in the list of Functions endpoints in Functions API, in the format
https://functions.<region-identifier>.oci.oraclecloud.com. Note that this is the preferred format. An older format (
https://functions.<region-identifier>.oraclecloud.com) is still supported, but is not preferred. The
<api-endpoint> is the identifier of the Oracle Cloud Infrastructure region in which you'll be creating and deploying functions. For example,
$ fn update context api-url https://functions.us-phoenix-1.oci.oraclecloud.com
Configure the new context with the address of the Docker registry that you want to use with Oracle Functions by entering:
$ fn update context registry <region-key>.ocir.io/<tenancy-namespace>/<repo-name>
<region-key> is the key of the Oracle Cloud Infrastructure Registry region. For example,
phx for Phoenix. See Availability by Region.
Oracle recommends that the Docker registry you specify is in the same region as the subnet on which you intend functions to run.
<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). For example, the namespace of the
acme-dev tenancy might be
ansh81vru1zp. Note that for some older tenancies, the namespace string might be the same as the tenancy name in all lower-case letters (for example,
<repo-name> is a repository name to pre-pend to the names of functions that you deploy.
$ fn update context registry phx.ocir.io/ansh81vru1zp/acme-repo
(Optional) Verify the Fn Project CLI context you've created by viewing the context file. For example, by entering:
$ more ~/.fn/contexts/johns-oci-context.yaml
When you have completed the steps in this topic, go on to 7. Set the Context for the Fn Project CLI Using the oracle.profile Parameter.