Quickstart

Build and deploy your first function

This guide will help you to create your first function using the Morty serverless platform. We apologize, we do not provide at today a sandbox environment where you can play with Morty in seconds. Be sure that it is on our roadmap and we will try to provide you a fully functional Morty environment soon.

Prerequisites

  • A Morty instance up and running. Please refer to the deployment guide to deploy Morty on your own infrastructure.
  • The Morty CLI (opens in a new tab) (>= 1.0.0) must be installed on your machine. You can install it using the following convenience script:
curl -fsSL https://morty-faas.github.io/install-cli.sh | sudo sh

Create your first function

In this section, you will create your first function with your favorite language. Morty has a notion of runtime. Multiple runtimes can be contributed for one specific language. You can list the available runtimes using the following command:

morty runtime list

You should have an output like :

Available runtimes:
- go-1.19
- node-19
- python-3
- rust-1.67

Choose your runtime based on what languages you prefer. For the rest of this document, we will use the go-1.19 runtime. You can find all the runtimes in the following GitHub repository (opens in a new tab) . You can now create a new function based on the chosen runtime:

morty fn init --runtime go-1.19 morty-quickstart

This command will create a directory morty-quickstart in your current working directory. This directory contains your function code. You can open it in your favorite IDE or code editor to check the files present. For a go-1.19 runtime, the folder structure will look like:

morty-quickstart
├── go.mod
├── handler.go
└── morty.yaml

The morty.yaml file is a special file that holds the function metadata. This file should not be removed and should be included in your version control. The handler.go file contains the function code, and the go.mod allows you to install external Go modules to empower your function.

You can customize your function as you want. When the function is ready, you are ready to build it.

Build the function

⚠️

This section requires an up and running Morty instance. If you don't have access to an instance, you can deploy your own instance by following the deployment guide.

In order to build and invoke your functions, you need to define a context in your CLI. A context is simply a configuration related to a specific Morty instance. Let's configure your context based on the Morty instance you target (replace ${MORTY_CONTROLLER_URL} and ${MORTY_REGISTRY_URL} by your own instance URLs) :

morty config add-context quickstart --controller ${MORTY_CONTROLLER_URL} --registry ${MORTY_REGISTRY_URL}

The added context is now the default context. You can now run the build of your function. The build command will send a build request to the registry, and once the build is done, the function will be provisioned through the controller. Execute the following command to build the function :

"Provisioned" means that the function was registered into the system but no instance was deployed. The deployment of one or more instances happens during the invocation of a function.

morty function build morty-quickstart

Your function is now ready to be invoked. Execute the following command and let the magic happen !

morty function invoke morty-quickstart
# output
{"message": "Hello, World!"}

Congratulations! You had successfully created and invoked your first function using Morty 🚀.