Getting started with Fn Project

Peter Jausovec
Sep 19, 2018 · 6 min read
“brown track and field” by Adi Goldstein

The Basics — install and run

This section goes through installing the Fn server, starting it and then creating a simple function and invoking it.

brew install fn
fn start
fnserver image running locally

First function

The Fn CLI comes with a init command that is used for creating new functions. The Fn CLI has been installed with brew during the previous step.

fn init --runtime go --trigger http hello
hello
├── Gopkg.toml
├── func.go
├── func.yaml
└── test.json
$ fn run
Building image hello:0.0.1 ...........
{"message":"Hello World"}
fn deploy --app myapp --local
Deploying the app to local Fn server
# List all triggers for 'myapp'
$ fn list triggers myapp
FUNCTION NAME TYPE SOURCE ENDPOINT
hello hello-trigger http /hello-trigger http://localhost:8080/t/myapp/hello-trigger
$ curl http://localhost:8080/t/myapp/hello-trigger
{"message":"Hello World"}

Grouping functions

To group the functions together, you can use the app name construct — this allows you to logically group different functions together (e.g. greeter-app could have functions called hello and goodbye).

# Create the greeter-app folder
mkdir greeter-app && cd greeter-app
# Create app.yaml that defines the app name
echo "name: greeter-app" > app.yaml
# Create a hello function in /hello subfolder
fn init --runtime go --trigger http hello
# Create a goodbye function in /goodbye subfolder
fn init --runtime go --trigger http goodbye
fn deploy --all --local
$ fn list triggers greeter-app
FUNCTION NAME TYPE SOURCE ENDPOINT
goodbye goodbye-trigger http /goodbye-trigger http://localhost:8080/t/greeter-app/goodbye-trigger
hello hello-trigger http /hello-trigger http://localhost:8080/t/greeter-app/hello-trigger
fn init --runtime node --trigger http
fn deploy --all --local
$ fn list triggers greeter-app
FUNCTION NAME TYPE SOURCE ENDPOINT
goodbye goodbye-trigger http /goodbye-trigger http://localhost:8080/t/greeter-app/goodbye-trigger
greeter-app greeter-app-trigger http /greeter-app-trigger http://localhost:8080/t/greeter-app/greeter-app-trigger
hello hello-trigger http /hello-trigger http://localhost:8080/t/greeter-app/hello-trigger

Enabling the UI

If you prefer UI to interact with Fn — there’s that for you as well. Assuming you have the Fn server running locally, you can start the UI like this:

docker run --rm -it --link fnserver:api -p 4000:4000 -e "FN_API_URL=http://api:8080" fnproject/ui
Fn server UI

Conclusion

This article should serve you as a good introduction and getting started document for Fn. It gives you the basics you need to start playing with serverless functions on your local machine.

Fn Project

Learn about the Fn Project, containers, and serverless computing!

Thanks to David Delabassee.

Peter Jausovec

Written by

— Kubernetes — Docker — Go — Python — React —

Fn Project

Learn about the Fn Project, containers, and serverless computing!