If one or more OCI Functions users is not a tenancy administrator:
Sign in to the Console as a tenancy administrator.
Open the navigation menu and select Identity & Security. Under Identity, select Policies.
Select Create Policy, specify a name and description for the new policy, and select the tenancy's root compartment.
Use the Policy Builder to create the policy. Select Functions from the list of Policy use cases, and base the policy on the policy template Let users create, deploy, and manage functions and applications.
The policy template includes the following policy statements:
Allow group <group-name> to use cloud-shell in tenancy
Allow group <group-name> to manage repos in tenancy
Allow group <group-name> to read objectstorage-namespaces in tenancy
Allow group <group-name> to manage logging-family in tenancy
Allow group <group-name> to read metrics in tenancy
Allow group <group-name> to manage functions-family in tenancy
Allow group <group-name> to use virtual-network-family in tenancy
Allow group <group-name> to use apm-domains in tenancy
Allow group <group-name> to read vaults in tenancy
Allow group <group-name> to use keys in tenancy
Allow service faas to use apm-domains in tenancy
Allow service faas to read repos in tenancy where request.operation='ListContainerImageSignatures'
Allow service faas to {KEY_READ} in tenancy where request.operation='GetKeyVersion'
Allow service faas to {KEY_VERIFY} in tenancy where request.operation='Verify'
If necessary, you can restrict these policy statements by compartment.
Open the navigation menu and select Developer Services. Under Functions, select Applications.
Select the region you're using with OCI Functions.
Select Create Application.
Specify:
helloworld-app as the name for the new application. You'll deploy your first function in this application, and specify this application when invoking the function.
The VCN and subnet in which to run the function. Note that a public subnet requires an internet gateway in the VCN, and a private subnet requires a service gateway in the VCN.
In a terminal window in your development environment:
Confirm that Docker is installed by entering:
Copy
docker version
If you see an error message indicating that Docker is not installed, you have to install Docker before proceeding. See the Docker documentation for your platform (for Oracle Linux, see here).
Assuming Docker is installed, go to the Prerequisites section of the Fn Project home page on GitHub and confirm that the installed version of Docker is at least the minimum version specified there. If not, re-install Docker before proceeding.
Launch the standard hello-world Docker image as a container to confirm that Docker is running by entering:
Copy
docker run hello-world
If you see an error message indicating that Docker is not running, you have to start the Docker daemon before proceeding. See the Docker documentation.
In the navigation bar, select the Profile menu and then select User settings or My profile, depending on the option that you see.
Under Resources, select API Keys, and then select Add API Key.
Select Generate API Key Pair in the Add API Key dialog.
Select Download Private Key and save the private key file (as a .pem file) in the ~/.oci directory. (If the ~/.oci directory doesn't already exist, create it now).
Select Add to add the new API signing key to your user settings.
The Configuration File Preview dialog is displayed, containing a configuration file snippet with basic authentication information for a profile named DEFAULT (including the fingerprint of the API signing key you just created).
Copy the configuration file snippet shown in the text box, and close the Configuration File Preview dialog.
In a text editor, open the ~/.oci/config file and paste the snippet into the file. (If the ~/.oci/config file doesn't already exist, create it now).
In the text editor, change the profile in the snippet you've just pasted, as follows:
Change the name of the profile from [DEFAULT] to a name of your choosing (for example, [functions-developer-profile]). Note that the ~/.oci/config file cannot contain two profiles with the same name.
Change the value of the key_file parameter of the profile to specify the path of the private key file (the .pem file) you downloaded earlier.
In the text editor, save the changes you've made to the ~/.oci/config file, and close the text editor.
In a terminal window, change permissions on the private key file (the .pem file) to ensure that only you can read it, by entering:
In a terminal window in your development environment:
Create a new Fn Project CLI context by entering:
Copy
fn create context <my-context> --provider oracle
Note that you specify --provider oracle to 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:
Copy
fn use context <my-context>
Configure the new Fn Project CLI context with the name of the OCI profile you've created for use with OCI Functions (for example, [functions-developer-profile]), by entering:
Configure the new context with the api-url endpoint to use when calling the OCI API by entering:
Copy
fn update context api-url <api-endpoint>
where <api-endpoint> is one of the endpoints in the list of Functions endpoints in the Functions API, in the format https://functions.<region-identifier>.oci.oraclecloud.com. For example:
Configure the Fn Project CLI context with the Oracle Cloud Infrastructure Registry address in the current region and tenancy that you want to use with OCI Functions:
where <repo-name-prefix> is a prefix of your choosing for the Oracle Cloud Infrastructure Registry repository in which to store images for the function. For example:
Configure the Fn Project CLI context with the OCID of the compartment for repositories to and from which you want OCI Functions to push and pull function images, by entering:
Change directory to the hello-java directory created in the previous step:
cd hello-java
Enter the following single Fn Project command to build the function and its dependencies as a Docker image called hello-java, push the image to the specified Docker registry, and deploy the function to OCI Functions in the helloworld-app application that you created earlier:
fn -v deploy --app helloworld-app
(Optional) Confirm that the function has been deployed to OCI Functions by selecting Functions (under Resources on the details page for the helloworld-app application) and noting that the hello-java function now appears.