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
andcontext
objects, and custom HTTP responses the Function returns.
NOTE: Read about Istio sidecars in Kyma and why you want them. Then, check how to enable automatic Istio sidecar proxy injection. For more details, see Default Istio setup in Kyma.
Steps
Follow these steps:
- Kyma CLI
- kubectl
- Kyma Dashboard
Export these variables:
Click to copyexport NAME={FUNCTION_NAME}export NAMESPACE={FUNCTION_NAMESPACE}Create your local development workspace.
a. Create a new folder to keep the Function's code and configuration in one place:
Click to copymkdir {FOLDER_NAME}cd {FOLDER_NAME}b. Create initial scaffolding for the Function using the dedicated CLI command:
Click to copykyma init function --name $NAME --namespace $NAMESPACECode 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 copycode .It's time to inspect the code and the
config.yaml
file. Feel free to adjust the "Hello World" sample code.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 copykyma apply functionb. Check if your Function was created successfully:
Click to copykubectl get functions $NAME -n $NAMESPACEYou should get a result similar to this example:
Click to copyNAME CONFIGURED BUILT RUNNING RUNTIME VERSION AGEtest-function True True True nodejs18 1 96s