Oracle Cloud Infrastructure Documentation

Creating, Deploying, and Invoking a Helloworld Function

You can start off using Oracle Functions by using Fn Project CLI commands to:

  • create a simple helloworld function written in java
  • push the image to the Docker registry that's configured for Oracle Functions
  • deploy the function to an application in Oracle Functions
  • invoke the function

Tip

If you aren't able to successfully complete one of the steps in this topic, review the solutions for common problems (see Troubleshooting Oracle Functions).

To get started with Oracle Functions:

  1. Confirm that you have completed the prerequisite steps for using Oracle Functions, as described in Preparing for Oracle Functions. Specifically, that you have:

  2. Log in to the Console as a functions developer.

  3. Use the Console to create a new application in Oracle Functions:

    1. In the Console, open the navigation menu. Under Solutions and Platform, go to Developer Services and click Functions.
    2. Select the region you intend to use for Oracle Functions. Oracle recommends that you use the same region as the Docker registry specified in the Fn Project CLI context (see 6. Create an Fn Project CLI Context to Connect to Oracle Cloud Infrastructure).
    3. 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 already defined in the compartment.

    4. Click Create Application and specify:

      • The name for the new application as helloworld-app.
      • The VCN and subnet (or subnets, up to a maximum of three) in which to run the function. For example, a VCN called acme-vcn-01 and a public subnet called Public Subnet IHsY:US-PHOENIX-AD-1). If a regional subnet has been defined, best practice is to select that subnet to make failover across availability domains simpler to implement. If a regional subnet has not been defined and you need to meet high availability requirements, select multiple subnets. Oracle recommends that subnets are in the same region as the Docker registry specified in the Fn Project CLI context (see 6. Create an Fn Project CLI Context to Connect to Oracle Cloud Infrastructure).

    5. Click Create.
  4. Log in to your development environment as a functions developer.

  5. In a terminal window, create a helloworld java function by entering:

     $ fn init --runtime java helloworld-func

    A directory called helloworld-func is created, containing:

    • A function definition file called func.yaml, containing the minimum amount of information required to build and run the function. See the Fn Project documentation to find out about the additional parameters you can include in a func.yaml file.
    • A /src directory containing source files and directories for the helloworld function (including /src/main/java/com/example/fn/HelloFunction.java).
    • A Maven configuration file called pom.xml that specifies the project artifacts and dependencies required to compile the function from the source files.
  6. Change directory to the newly created helloworld-func directory.
  7. Enter the following single Fn Project command to build the function and its dependencies as a Docker image called helloworld-func, push the image to the specified Docker registry, and deploy the function to Oracle Functions in the helloworld-app:

     $ fn -v deploy --app helloworld-app

    The -v option simply shows more detail about what Fn Project commands are doing (see Using the Fn Project CLI with Oracle Functions).

  8. (Optional) Assuming the specified Docker registry is Oracle Cloud Infrastructure Registry, use the Console to confirm that the helloworld-func image has been pushed to Oracle Cloud Infrastructure Registry successfully:
    1. In the Console, open the navigation menu. Under Solutions and Platform, go to Developer Services and click Registry.
    2. Choose the registry's region.

      You see all the repositories in the registry to which you have access. The image you pushed is in a new repository with a name constructed from:

      For example, the new repository might be called acme-repo/helloworld-func.

    3. Click the name of the new repository. You see details of the helloworld-func image that's been pushed to Oracle Cloud Infrastructure Registry.
  9. (Optional) Use the Console to confirm that the function has been deployed to Oracle Functions successfully:
    1. In the Console, open the navigation menu. Under Solutions and Platform, go to Developer Services and click Functions.
    2. 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 that an application called helloworld-app has been created.

    3. Click the helloworld-app application to see the functions within it.

      The Functions page shows that the helloworld-func function has been deployed to Oracle Functions.

  10. In a terminal window, invoke the helloworld-func function by entering:

     $ fn invoke helloworld-app helloworld-func

    The 'Hello World !' message is displayed.

Congratulations! You've successfully created and deployed your first function to Oracle Functions!