This blog post is the 3rd part of the Deliver real-life use cases with SAP BTP – Returnable Packaging technical enablement session:
Part 1: Deliver real-life use cases with SAP BTP – Returnable Packaging
Part 2: Deliver real-life use cases with SAP BTP – Returnable Packaging – SAP AI Core – coming soon
Part 3: Deliver real-life use cases with SAP BTP – Returnable Packaging – SAP Kyma – this blog
Part 4: Deliver real-life use cases with SAP BTP – Returnable Packaging – SAP Build Apps – coming soon
Check the full set of our Deliver real-life use cases with SAP BTP series calendar here to watch the recordings of past sessions and register for the upcoming ones!
In our previous blog Deliver real-life use cases with SAP BTP – Returnable Packaging we presented the Returnable Packaging use case and showed several architecture options. The selected architecture has Kyma as the runtime for our AI-powered Returnable Packaging server-side application. In this blog I’ll like to deep dive into the Kyma topic by showing you how the application was developed.
Let’s refresh our mind with a short recap of the scenario. We saw that each time a new bottle is returned, the Smart Returnable Packaging Station calls an API offered by our AI-powered Returnable Packaging prototype running in SAP Business Technology Platform. The bottle picture as well as some other details (like the returnable packaging station machineId and the consumer userId) are sent as parameters.
To implement the backend, we have chosen the Kyma runtime, and we have leveraged its Serverless module to reduce the implementation and operation effort of our prototype. We have implemented a lightweight serverless function using Node.js (Python is also a possible option), by simply developing our function code snippets without having to build and maintain a container image or its infrastructure.
Our SAP Kyma Serverless function main tasks are:
Before we go in detail to the implementation of our prototype let me shortly introduce Kyma.
SAP BTP Kyma runtime provides a fully managed cloud-native Kubernetes application runtime based on the open-source project “Kyma”. Based on modular building blocks, Kyma runtime includes all the necessary capabilities to simplify the development and to run enterprise-grade cloud-native applications.
Kyma environment permits a native consumption of the Multi-Cloud Foundation Services and a smooth consumption of SAP and non-SAP applications. It also supports out-of-the-box CAP, SAP Cloud SDK, application router, and HTML5 deployer.
Every Kyma environment consists of:
Kyma Serverless Module offers a Kubernetes-based platform on which you can build, run, and manage serverless applications in Kubernetes. These applications are called Functions, and they are based on the Function custom resource (CR) objects. They contain simple code snippets that implement specific business logic.
Serverless in Kyma allows you to reduce the implementation and operation effort of an application to the absolute minimum. It provides a platform to run lightweight Functions in a cost-efficient and scalable way using Phyton and Node.js.
Note: “Serverless” refers to an architecture in which the infrastructure of your applications is managed by cloud providers. Because the resource allocation can be dynamic and depends on your current needs, the serverless model is particularly cost-effective when you want to implement a certain logic that is triggered on demand. Simply, you get your things done and don’t pay for the infrastructure that stays idle. Check the Serverless tutorials for more details.
To implement a Kyma serverless function you can directly go to you Kyma cockpit and edit the different components composing your function: Code, Dependencies, Configuration and Resources.
But if you want to keep track of your development with a versioning tool, like Git for example, it will be more convenient to use a code editor. In our case to develop our Kyma serverless function we have used Microsoft Visual Studio and leveraged the SAP HANA Academy Function-as-a-service Yeoman Generator, to jump-start our Function-as-a-Service application. You can get all details about the code generator in this Youtube playlist SAP Business Technology Platform – Serverless Functions.
The SAP HANA Academy Function-as-a-service Yeoman Generator gathers from you information about the different features you want to get implemented for your application and generates a skeleton for your application leveraging Helm Charts. A Helm Chart is a collection of files that describe a related set of Kubernetes resources. A single chart might be used to deploy something simple, like a memcached pod, or something complex, like a full web app stack with HTTP servers, databases, caches, and so on.
For our prototype, the code generator created 2 main modules:
The Database module will be deployed as a Job and run at the start of our function.
This module will take care of creating the required database artifacts in SAP HANA Cloud to store the returns history like tables, stored procedures,…
A main srv module that will be deployed as a function and will expose the APIs for both the Smart Returnable Packaging Station as well as for consumer to check his/her loyalty points and sustainability goals.
The APIs exposed by the main module are:
The services consumed by this main module are:
If you want to get the full code of our Kyma serverless function please check our Git repository.
Implementation details about each one of the components of our use case are explained in a separated blog, check them to learn more!
Part 1: Deliver real-life use cases with SAP BTP – Returnable Packaging
Part 2: Deliver real-life use cases with SAP BTP – Returnable Packaging – SAP AI Core – coming soon
Part 3: Deliver real-life use cases with SAP BTP – Returnable Packaging – SAP Kyma – this blog
Part 4: Deliver real-life use cases with SAP BTP – Returnable Packaging – SAP Build Apps – coming soon
Here are some links to additional resources that can get you up to speed with Kyma.
Learn
Implement
Engage