Creating Code-only Functions

Find out how to create code-only functions in OCI Functions by selecting a supported runtime and providing a function archive.

Create a code-only function when you want to deploy a function from an archive rather than from a container image.

Before creating the function, package the function source and dependencies according to the selected runtime and the architecture of the OCI Functions application.

Before creating a code-only function, you need:

  • Access to an OC1 region where code-only functions are available.
  • An existing OCI Functions application.
  • Permissions to create and update Functions resources.
  • A supported OCI Functions managed runtime for the code-only function: Go, Java, Node.js, or Python.
  • A function archive that follows the archive requirements for the selected runtime and application architecture.
  • If using Object Storage as the archive source, access to the bucket and object that contain the archive.
  • If using Object Storage as the archive source, a policy that allows the OCI Functions application resource principal to read the archive object.

Using the Console

To create a code-only function:

  1. On the Applications list page, select the application in which you want to create the function. If you need help finding the list page or the application, see Listing Applications.
  2. Select the Functions tab.

    The Functions list page opens. All functions in the selected application are displayed in a table.

  3. Select Create from archive, and specify the following details:
    • Name: A name for the new function. Avoid entering confidential information.
    • File source: Specify the archive to use by specifying the following details:
      • Select from object storage: Select the Object Storage compartment and bucket that contains the archive, and specify the name and version (if applicable) of the archive. Maximum file size is 250 MB.
      • Upload from your device: Select the archive file, or drag and drop the file into the box. Maximum file size is 25 MB.
      • Runtime: Select a supported runtime to determine the managed execution environment used by OCI Functions.
      • Handler: If the runtime you select requires a handler, enter the handler. For some runtimes, a code-only function requires a handler. The handler identifies the entry point in the function archive that OCI Functions calls when the function is invoked.

        For Java, Python, and Node.js code-only functions, you must specify a handler when you create the function.

        For Go code-only functions, do not specify a separate handler value. The archive must contain a Linux executable named func in the required location.

  4. Specify the following details:

    • Memory (in MBs): The maximum amount of memory that the function can use while running.
    • Synchronous invocation timeout (in seconds): The maximum amount of time that the function can run for, when invoked in Sync mode. For more information about invoking functions in Sync mode, see Invoking Functions.
    • Detached invocation configuration: Specify how to run the function, when invoked in Detached mode:
      • Detached invocation timeout (in seconds): The maximum amount of time that the function can run for, when invoked in Detached mode.
      • Success destination: (optional) When the function is invoked in Detached mode, the destination to which to write invocation records when the detached invocation succeeds. Supported destinations for the results of detached invocations are the Notifications service, the Queue service, and the Streaming service. Depending on the destination you select, you are prompted to enter additional details (for example, in the case of the Notifications service, you select a Topic compartment and a Topic). To write to the destination service, OCI Functions requires IAM permissions. If the necessary permissions do not already exist, you are prompted to confirm that you want a suitable IAM policy created for you (see Creating IAM Policies for Detached Invocation Success and Failure Destinations).
      • Failure destination: (optional) When the function is invoked in Detached mode, the destination to which to write invocation records when the detached invocation fails. Supported destinations for the results of detached invocations are the Notifications service, the Queue service, and the Streaming service. Depending on the destination you select, you are prompted to enter additional details (for example, in the case of the Notifications service, you select a Topic compartment and a Topic). To write to the destination service, OCI Functions requires IAM permissions. If the necessary permissions do not already exist, you are prompted to confirm that you want a suitable IAM policy created for you (see Creating IAM Policies for Detached Invocation Success and Failure Destinations).

      For more information about invoking functions in Detached mode, see Invoking Functions.

    • 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.

    • Tags: 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.
  5. Select Create to create the function.

The code-only function is created. You can invoke it like any other function.

Using the CLI

Using the OCI CLI

Having packaged a function archive, you can use the OCI CLI to create the code-only function.

  • Create a code-only function that uses an archive in Object Storage by entering:

    oci fn function create archive-function object-storage fn-update-runtime-config --application-id <app-id> --bucket-name <bucket-name> --display-name <display-name> --functions-runtime-name <functions-runtime-name> --memory-in-mbs <memory> --namespace <namespace> --object-name <object-name>
  • Create a code-only function that uses an uploaded archive file by entering:

    oci fn function create archive-function direct-archive fn-update-runtime-config --application-id <app-id> --display-name <display-name> --functions-runtime-name <functions-runtime-name> --memory-in-mbs <memory> --archive-file file:/<archive-file-path>

For a complete list of flags and variable options for OCI CLI commands, see the Command Line Reference.

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.

When using the Fn Project CLI, you can create a code-only function in two ways:

Explicitly creating a code-only function using the fn create command

Having packaged a function archive, you can use the Fn Project CLI to create a code-only function.

To create a code-only function from a directly uploaded archive file, use the following syntax:

fn create function <app-name> <function-name> \
  --code-only \
  --source-type direct \
  --source-file <path-to-function-source.zip> \
  --runtime-config-type function-update \
  --runtime-name <runtime-name> \
  --handler <handler>

To create a code-only function from an archive in Object Storage, use the following syntax:

fn create function <app-name> <function-name> \
  --code-only \
  --source-type object-storage \
  --bucket-name <bucket> \
  --namespace <namespace> \
  --object-name <object-name.zip> \
  --runtime-config-type function-update \
  --runtime-name <runtime-name> \
  --handler <handler>

For example:

fn create function acmeapp acme-func \
  --code-only \
  --source-type object-storage \
  --bucket-name MyBucket \
  --namespace axaxnpcrorw5 \
  --object-name hello-java.zip \
  --runtime-config-type function-update \
  --runtime-name java21.ol9 \
  --handler com.example.fn.HelloFunction::handleRequest

To list available runtimes, enter fn list runtimes. To list runtime versions for a runtime, enter fn list runtime-versions --runtime-name <runtime-name>.

For Go code-only functions, do not specify a separate handler value. The archive must contain a Linux executable named func in the required location.

Implicitly creating a code-only function using the fn init, fn build, and fn deploy commands

You can use the Fn Project CLI implicit developer flow to create a code-only function from a local function directory. In this flow, the Fn Project CLI uses the function metadata in func.yaml and the current Fn Project CLI context to package and deploy the function.

Use this flow when you want the Fn Project CLI to manage the local archive packaging and deployment workflow.

Before using the implicit developer flow, confirm that the active Fn Project CLI context is set to the compartment and region where you want to create the function. The context can also affect how the Fn Project CLI handles code-only function archives during deployment.

If you want to use Object Storage for code-only function archives, specify the Object Storage bucket name and namespace in the Fn Project CLI context. For example, by entering:

fn update context object_storage_bucket_name <source-bucket-name>
fn update context object_storage_namespace <object-storage-namespace>

When the object_storage_bucket_name and object_storage_namespace values are present in the active Fn Project CLI context, the implicit developer flow can use Object Storage for code-only function archives. To use direct archive upload instead, remove these values from the context, or switch to a different Fn Project CLI context that does not include them.

To create a code-only function using the implicit developer flow:

  1. Initialize a code-only function directory by entering:

    fn init --code-only --runtime-name <runtime-name> --runtime-config-type function-update
  2. Build the function archive by entering:

    fn build
  3. Deploy the function by entering:

    fn deploy --app <app-name>
Note

If the Fn Project CLI context is configured to use Object Storage for code-only function archives:

  • You can enter fn deploy to build the function archive, upload the archive to Object Storage, and deploy the function.
  • You can enter fn push to simply upload the archive to Object Storage without deploying the function.

Using the API

Run the CreateFunction operation to create a function.