Function-as-a-service in Kyma environment

Objectives

After completing this lesson, you will be able to:

  • Function-as-a-service in Kyma environment

Function-as-a-service in Kyma environment

Kyma offers a service known as Function-as-a-service that provides a platform on which you can build, run and manage serverless applications in Kubernetes. This allows customers to execute code without having to manage the underlying infrastructure associated with it. They contain simple code snippets that implement a specific business logic. For example, you can have a function that compresses pictures before storing them in a remote location. This lesson will give you a brief insight on how to leverage SAP Cloud SDK when creating these functions.

Executing functions

Code snippets exposed as function-as-a-service can be executed in the following ways.

  • Triggered by business events coming from external sources. You can subscribe to them using a Subscription CR.
  • Exposed as an external endpoint (HTTP). You can define who can reach the endpoint and the operations they can perform on it using an APIRule CR.

Runtimes

Currently, you can create functions in both Node.js (16, 18) and Python (3.9) in the Kyma environment. In addition, you can choose where you want to keep your function’s source code and dependencies.

  • You can place them directly in the Function CR under the spec.source and spec.deps fields as an inline function
  • You can store the code and dependencies in a public or private Git repository (Git functions)

Storing code in Git repository ensures your function is versioned and gives you more development freedom in the choice of project structure or an IDE.

SAP Cloud SDK and Function-as-a-service

More than likely your function will require some form of authentication and authorization. In addition, it will require access to the destination service and require access to remote services. In these scenarios, you can use the SAP Cloud SDK to connect to destination services and remote services.

Under Service Management → Service Instances, you can define your uaa and destination service instances for the function. Also, under Service Management → Service Bindings, the bindings are created for the service instances during deployment.

Credentials for connecting to the service instances are set up in the Configuration → Secrets. Within the function code, we can use secretMounts and this allows us to access the secrets of the uaa or destination service instances. SAP Cloud SDK can automatically read these values, so no additional configuration is required.

Log in to track your progress & complete quizzes