Oracle Cloud Infrastructure Documentation

Creating Functions from Existing Docker Images

You can create a new function definition in the Oracle Functions server in different ways:

  • Using the Console or the Fn Project CLI command fn create function to create a new function based on an existing Docker image that has already been pushed to the Docker registry (as described in this topic).
  • Using the single Fn Project CLI command fn deploy to build a new Docker image, push the image to the Docker registry, and create a new function based on the image in one step (as described in Creating and Deploying Functions).
  • Using the API (see CreateFunction).

When using the Console or the fn create function command to create a new function based on an existing Docker image, you specify function metadata to store in the Oracle Functions server. For example, the maximum length of time the function is allowed to execute for.

The existing image on which you base a new function must be suitable for use with Oracle Functions. Typically, to build and push a suitable image, you or somebody else will use Fn Project CLI commands and/or Docker CLI commands. For example, having written your function code and a func.yaml file containing function metadata (perhaps based on the template helloworld function and func.yaml created using fn init), you can:

  • Use fn build to build a new Docker image from the function.
  • Use docker push to push the image to the Docker registry.

With the image in the Docker registry, you can then use the Console to create a function based on the image, as described in this topic.

Using the Console

To use the Console to create a new function in the Oracle Functions server from an existing Docker image that has already been pushed to the Docker registry:

  1. Log in to the Console as a functions developer.
  2. In the Console, open the navigation menu. Under Solutions and Platform, go to Developer Services and click Functions.
  3. Select the region you are using with Oracle Functions. Oracle recommends that you use the same region as the Docker registry that's specified in the Fn Project CLI context (see 6. Create an Fn Project CLI Context to Connect to Oracle Cloud Infrastructure).
  4. Select the compartment specified in the Fn Project CLI context (see 6. Create an Fn Project CLI Context to Connect to Oracle Cloud Infrastructure).

    The Applications page shows the applications defined in the compartment.

  5. Click the name of the application in which you want to create the new function.

  6. Click Create Function and specify:
    • Name: A name for the new function.
    • Image: The existing image in the Oracle Cloud Infrastructure Registry in your currently selected region. You first select the image repository, and then the image version.
    • Memory: The maximum amount of memory the function can use during execution.
    • Timeout: The maximum amount of time the function will be allowed to run for.
    • Tags: Optionally, you can apply tags. If you have permissions to create a resource, 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 are not sure if you should apply tags, skip this option (you can apply tags later) or ask your administrator.
  7. Click Create to create the new function in the Oracle Functions server.

The new function is shown in the Console, in the list of functions in the application you selected.

Using Fn Project CLI Commands

To use the Fn Project CLI to create a new function in the Oracle Functions server from an existing Docker image that has already been pushed to the Docker registry:

  1. Log in to your development environment as a functions developer.

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

    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 Oracle Functions, based on the existing image and with the name you specified

  3. 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 API

For information about using the API and signing requests, see REST APIs and Security Credentials. For information about SDKs, see Software Development Kits and Command Line Interface.

Use these API operations to manage functions: