Create an inline Function

This tutorial shows how you can create a simple "Hello World" Function in Node.js. The Function's code and dependencies are defined as an inline code in the Function's spec.

TIP: Serverless also allows you to store the Function's code and dependencies as sources in a Git repository. To learn more, read how to Create a Git Function.

TIP: Read about Function’s specification if you are interested in its signature, event and context objects, and custom HTTP responses the Function returns.

Steps

Follow these steps:

  • Kyma CLI
  • kubectl
  • Kyma Dashboard
  1. Export these variables:

    Click to copy
    export NAME={FUNCTION_NAME}
    export NAMESPACE={FUNCTION_NAMESPACE}
  2. Create your local development workspace.

    a. Create a new folder to keep the Function's code and configuration in one place:

    Click to copy
    mkdir {FOLDER_NAME}
    cd {FOLDER_NAME}

    b. Create initial scaffolding for the Function using the dedicated CLI command:

    Click to copy
    kyma init function --name $NAME --namespace $NAMESPACE
  3. Code and configure.

    Open the workspace in your favorite IDE. If you have Visual Studio Code installed, run the following command from the terminal in your workspace folder:

    Click to copy
    code .

    It's time to inspect the code and the config.yaml file. Feel free to adjust the "Hello World" sample code.

  4. Deploy and verify.

    a. Call the apply command from the workspace folder. It will build the container and run it on the Kyma runtime pointed by your current KUBECONFIG file:

    Click to copy
    kyma apply function

    b. Check if your Function was created successfully:

    Click to copy
    kubectl get functions $NAME -n $NAMESPACE

    You should get a result similar to this example:

    Click to copy
    NAME CONFIGURED BUILT RUNNING RUNTIME VERSION AGE
    test-function True True True nodejs18 1 96s