Passing Custom Configuration Parameters to Functions

The code in functions you deploy to OCI Functions will typically require values for different parameters. Some pre-defined parameters are available to your functions as environment variables. But you'll often want your functions to use parameters that you've defined yourself. For example, you might create a function that reads from and writes to a database. The function will require a database connect string, comprising a username, password, and hostname. You'll probably want to define username, password, and hostname as parameters that are passed to the function when it's invoked.

To pass user-defined parameters to a function deployed in OCI Functions, you create key-value pairs known as custom configuration parameters. You can create custom configuration parameters that are:

  • application-wide, meaning they are passed to every function in an application
  • function-specific, meaning they are passed to the particular function for which they are defined (function-specific parameters override application-wide parameters with the same name)

To create custom configuration parameters, you can use:

  • the config: section of a function's func.yaml file, to define function-specific custom configuration parameters
  • the Console and the Fn Project CLI, to define both application-wide and function-specific custom configuration parameters

OCI Functions combines all the custom configuration parameters (both application-wide and function-specific) in the application into a single, serially-encoded configuration object with a maximum allowable size of 4Kb.

Using the Console

To specify custom configuration parameters to pass to functions using the Console:

  1. Sign in to the Console as a functions developer.
  2. In the Console, open the navigation menu and click Developer Services. Under Functions, click Applications.
  3. Select the region you are using with OCI Functions. Oracle recommends 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).
  4. 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.

  5. Click the name of the application containing functions to which you want to pass custom configuration parameters:

    • To pass one or more custom configuration parameters to every function in the application, click Configuration to see the Configuration section for the application.

    • To pass one or more custom configuration parameters to a particular function, click the function's name to see the Configuration section for the function.

  6. In the Configuration section, specify details for the first custom configuration parameter:

    • Key: The name of the custom configuration parameter. The name must only contain alphanumeric characters and underscores, and must not start with a number. For example, username
    • Value: A value for the custom configuration parameter. The value must only contain printable unicode characters. For example, jdoe
  7. Click the plus button to save the new custom configuration parameter.

    OCI Functions combines the key-value pairs for all the custom configuration parameters (both application-wide and function-specific) in the application into a single, serially-encoded configuration object with a maximum allowable size of 4Kb. You cannot save the new custom configuration parameter if the size of the serially-encoded configuration object would be greater than 4Kb.

  8. (Optional) Enter additional custom configuration parameters as required.

Using Fn Project CLI Commands

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 specify custom configuration parameters to pass to functions using the Fn Project CLI:

  1. Log in to your development environment as a functions developer and open a terminal window.

  2. To specify one or more custom configuration parameters to pass to every function in an existing application, enter:

    fn config app <app-name> <key> <value>

    where:

    • <app-name> is the name of the application containing the functions to which you want to pass the custom configuration parameter.
    • <key> is the name of the custom configuration parameter. The name must only contain alphanumeric characters and underscores, and must not start with a number.
    • <value> is the value to give to the custom configuration parameter. The value must only contain printable unicode characters.

    For example:

    fn config app acmeapp username jdoe

    Note the following:

    • You can also define application-wide custom configuration parameters when you create a new application using the fn create app command.
    • OCI Functions combines the key-value pairs for all the custom configuration parameters (both application-wide and function-specific) in the application into a single, serially-encoded configuration object with a maximum allowable size of 4Kb.
  3. To specify one or more custom configuration parameters to pass to a particular function, enter:

    fn config function <app-name> <function-name> <key> <value>

    where:

    • <app-name> is the name of the application containing the function to which you want to pass the custom configuration parameter.
    • <function-name> is the name of the function to which to pass the custom configuration parameter.
    • <key> is the name of the custom configuration parameter. The name must only contain alphanumeric characters and underscores, and must not start with a number.
    • <value> is the value to give to the custom configuration parameter. The value must only contain printable unicode characters.

    For example:

    fn config function acmeapp acme-func username jdoe

    Note the following:

    • You can also define function-specific custom configuration parameters when you create a new function using the fn create function command.
    • OCI Functions combines the key-value pairs for all the custom configuration parameters (both application-wide and function-specific) in the application into a single, serially-encoded configuration object with a maximum allowable size of 4Kb.