Serverless computing has revolutionized how developers build and deploy applications by abstracting away infrastructure management and allowing focus solely on code and business logic. SAP Kyma embraces this paradigm through Kyma Functions, a key feature enabling developers to build lightweight, event-driven serverless applications directly within the Kyma environment.
This article explores how to build serverless applications using Kyma Functions and why they are an essential part of extending SAP solutions in the cloud-native era.
Kyma Functions are small, stateless pieces of code that run in response to events or HTTP requests. They are executed on-demand without the need to manage the underlying infrastructure such as servers or containers explicitly. Kyma provides a runtime environment for these functions, managing scaling, availability, and security seamlessly.
Kyma Functions support multiple programming languages (like Node.js, Python, and Go) and are tightly integrated with Kyma’s eventing system and API Gateway.
kubectl and configure it to access your Kyma cluster.Create a function that responds to HTTP requests. For example, a Node.js function that returns a greeting.
module.exports = {
main: async function(event, context) {
return {
statusCode: 200,
body: JSON.stringify({ message: "Hello from Kyma Function!" }),
};
},
};
Write a function.yaml manifest describing your function:
apiVersion: serverless.kyma-project.io/v1alpha1
kind: Function
metadata:
name: hello-function
spec:
runtime: nodejs14
source: |
module.exports = {
main: async function(event, context) {
return {
statusCode: 200,
body: JSON.stringify({ message: "Hello from Kyma Function!" }),
};
},
};
type: HTTP
Deploy your function to the Kyma cluster:
kubectl apply -f function.yaml
Create an API rule to expose your function through Kyma’s API Gateway:
apiVersion: gateway.kyma-project.io/v1alpha1
kind: APIRule
metadata:
name: hello-function-apirule
spec:
gateway: kyma-gateway.kyma-system.svc.cluster.local
service:
name: hello-function
port: 8080
rules:
- path: /.*
methods: ["GET"]
accessStrategies:
- handler: noop
Apply it:
kubectl apply -f apirule.yaml
Get the URL from the API Rule and send a request:
curl https://<your-api-host>/hello
You should receive the greeting message from your Kyma function.
Kyma Functions empower SAP developers to build agile, scalable, and event-driven serverless applications that extend SAP solutions efficiently. By reducing operational overhead and enabling rapid iterations, Kyma Functions accelerate innovation within the SAP Business Technology Platform and cloud-native landscapes.
Whether you want to automate simple tasks or build complex event-driven extensions, Kyma Functions offer a powerful and flexible toolset to achieve your goals.