Difficulty: beginner
Estimated Time: 30 minutes

This scenario introduces serverless Functions with Project Fn. It was originally prepared for the Meetup Workshop Cloud Native application development on Oracle Cloud Infrastructure in January 2020, hosted by AMIS|Conclusion in Nieuwegein in collaboration with REAL (the Red Expert Alliance) and Link from Portugal. It was updated for the REAL OCI Handson Webinar Series that started in June 2020

The scenario uses an Ubuntu 20.04 environment with embedded browser based VS Code, Docker, Fn CLI and Fn Server running locally. It does not require an OCI Cloud instance.

You will create Functions locally and deploy them to the local Fn Server. Functions can then be invoked through the Fn CLI or through regular HTTP clients such as CURL. You will get some guidance on debugging and logging.

In step 3. you will look at testing the function - both locally, before deployment (using Jest) as well as remotely after deployment - for functionality (with Newman) and performance (using Apache Bench).

In step 4, you will look at passing (environment specific) context variables to the function's runtime deployment

The scenario works with Node (JS) and Java as runtime languages. You can experiment with Go, Ruby, Python as runtimes just as easily.

The scenario offers two bonus steps: one let's you create a Java function implemented with a GraalVM powered natively executable image (small size and faster startup ) and the other one demonstrates how any custom Docker Container image can provide the implementation of an Fn function.

Overview of Function running on Fn


This completes your explorations with Functions on a local Fn Server. The next scenario you may want to explore looks at deploying Function to Oracle Cloud Infrastructure.

Background Resources

Tutorial Getting Started with Fn environment https://github.com/fnproject/tutorials/blob/master/install/README.md

Tutorial FN with Node https://github.com/fnproject/tutorials/blob/master/node/intro/README.md

Docs on Fn on OCI https://docs.cloud.oracle.com/iaas/Content/Functions/Tasks/functionscreatefncontext.htm

Tutorials and other background resource for Project Fn: https://github.com/fnproject/tutorials/blob/master/README.md

Serverless Functions with Project Fn

Step 1 of 8

Step 1 - Install Fn and OCI environment

In this step, we will together prepare the environment for working with Fn. The Katacoda scenario environment runs Ubuntu and contains Docker. We need to add Fn CLI and Fn Server.

Wait for the Fn Server to be running

In the background we are currently preparing your Fn environment. Several Docker images are pulled and the Fn server is started. This takes up to three minutes. You can check if Fn Server is running by checking the currently running Docker containers using the following command:

docker ps

Do not continue until you see a Docker container running based on image fnproject/fnserver:latest Fn Server is running

Get going with Fn

Check the installed version - client and server - of Fn

fn version

List the currently available Fn contexts

fn list contexts

Notice we have a default context which deploys to a local Fn server. The default context is created the first time you run the Fn CLI. However, we need to select default as our current context and set a registry value for remote or local Docker use.

The currently active context is default - this is a local context that uses the locally running Fn server for deploying functions.

Before we start using Fn, we need to configure Fn to point to an appropriate Docker registry so it knows where to push your function images to. Normally Fn points to your Docker Hub account by specifying your Docker Hub username. However, for pure local development we can simply configure Fn with an arbitrary value

So now update the registry setting for the default context to something meaningless.

fn update context registry something-meaningless

You can list the currently available Fn contexts again and see whether your changes had an effect (of course they did)

fn list contexts