Creating 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.
If you are using Cloud Shell as your development environment, two Fn Project CLI contexts have already been created for you (a default context and a context for the current region). For more information, see Oracle Functions on Cloud Shell QuickStart Guide. You simply have to copy and paste commands from the Getting Started page into the Cloud Shell window:
- to instruct the Fn Project CLI to use the context for the current region
- to provide the OCID of the compartment that will own deployed functions
- to provide the Oracle Cloud Infrastructure Registry address that you want to use with Oracle Functions
The instructions in this topic assume:
- you are not using Cloud Shell as your development environment
- you are using Linux
- you have already completed the steps in Installing 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
Note that you specify
--provider oracleto enable authentication and authorization using Oracle Cloud Infrastructure request signing, private keys, user groups, and policies that grant permissions to those user groups.
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 Creating 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
<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-prefix>
<region-key>is the key of the Oracle Cloud Infrastructure Registry region. For example,
phxfor 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-devtenancy 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-prefix>is a repository name prefix 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:
The context file contains:
api-url: https://functions.us-phoenix-1.oci.oraclecloud.com provider: oracle registry: phx.ocir.io/ansh81vru1zp/acme-repo
When you have completed the steps in this topic, go on to Setting the Context for the Fn Project CLI Using the oracle.profile Parameter.