Creating a Function
Find out how to create functions in the OCI Functions server from an existing Docker image that has already been pushed to the Docker registry.
For prerequisites and more information, see Creating Functions.
- Sign in to the Console as a functions developer.
- Open the navigation menu and click Developer Services. Under Functions, click Applications.
- Select the region you're using with OCI Functions.
We recommend that you use the same region as the Docker registry that's specified in the Fn Project CLI context. See Creating an Fn Project CLI Context to Connect to Oracle Cloud Infrastructure.
-
Select the compartment specified in the Fn Project CLI context. See Creating an Fn Project CLI Context to Connect to Oracle Cloud Infrastructure.
The Applications page shows the applications defined in the compartment.
-
Click the name of the application in which you want to create the function.
- Click the Create Function button, select Create from existing image, and specify the following details:
- Name: A name for the new function. Avoid entering confidential information.
- Repository: The repository in the OCI Container Registry in the current region that contains the image.
- Image: The existing image in the OCI Container Registry repository in the current region. The image architecture must be compatible with the application's shape (see Specifying the Compute Architecture on Which to Run Functions).
- Memory: The maximum amount of memory that the function can use while running.
- Timeout: The maximum amount of time that the function can run for.
- Enable provisioned concurrency: You can minimize any initial delays when invoking the function by specifying a minimum number of concurrent function invocations for which you want to have execution infrastructure constantly available.
If you select this option, you enter a value for Provisioned concurrency units (PCUs) to specify the minimum number of concurrent function invocations. The actual PCUs value you enter must be a multiple of 10. If Memory is set to 256 MB, the PCUs value must be a multiple of 20; if Memory is set to 128 MB, the PCUs value must be a multiple of 40. The total number of PCUs available depends on the size of the function, the tenancy limit, and whether provisioned concurrency has been enabled for other functions in the tenancy. For more information about provisioned concurrency, see Reducing Initial Latency Using Provisioned Concurrency.
- Tagging options: If you have permissions to create a resource, then you also have permissions to apply free-form tags to that resource. To apply a defined tag, you must have permissions to use the tag namespace. For more information about tagging, see Resource Tags. If you're not sure whether to apply tags, skip this option or ask an administrator. You can apply tags later.
-
Select one of the following options:
- To create the function in the OCI Functions server now, click Create. The new function is shown in the Console, in the list of functions in the application you selected.
- To create the function later using Resource Manager and Terraform, click Save as stack to save the resource definition as a Terraform configuration. For more information about saving stacks from resource definitions, see Creating a Stack from a Resource Creation Page.
Using the Fn Project CLI
Tip
From time to time, new versions of the Fn Project CLI are released. We recommend you regularly check that the latest version is installed. For more information, see Steps to upgrade the Fn Project CLI.To use the Fn Project CLI to create a new function in the OCI Functions server from an existing Docker image that has already been pushed to the Docker registry:
-
Log in to your development environment as a functions developer.
-
In a terminal window, create a new function by entering:
fn create function <app-name> <function-name> <image-name>
where:
<app-name>
is the name of an existing application in which to create the new function.<function-name>
is the name of the new function you want to create. Avoid entering confidential information.<image-name>
is the name of the existing image in the Docker registry on which to base the new function. The image architecture must be compatible with the application's shape (see Specifying the Compute Architecture on Which to Run Functions).
For example:
fn create function acmeapp acme-func phx.ocir.io/ansh81vru1zp/acme-repo/acme-func:0.0.3
A new function is created in OCI Functions, based on the existing image and with the name you specified
-
Verify that the new function has been created by entering:
fn list functions <app-name>
For example:
$ fn list functions acme-app NAME IMAGE acme-func phx.ocir.io/ansh81vru1zp/acme-repo/acme-func:0.0.3
Using the OCI CLI
Use the oci fn function create command and required parameters to create a function:
oci fn function create --application-id <application-ocid> --display-name <function-name> --memory-in-mbs <memory> [OPTIONS]
For a complete list of flags and variable options for OCI CLI commands, see the Command Line Reference.
-
Run the CreateFunction operation to create a function.