Part 3: Deliver real-life use cases with SAP BTP – Returnable Packaging – SAP Kyma

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:

  • Consume the AI Computer Vision Models APIs we deployed in SAP AI-Core to detect the bottle’s types.
  • Store all the returns data in SAP HANA Cloud.
  • Post the return documents in the SAP Returnable Packaging Management Industry Cloud solution through its oData APIs, that will be cascaded via Integration Suite flows to the SAP S/4 HANA Cloud backend.

What is Kyma?

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:

  • A Kubernetes cluster based on project “Gardener” on a cloud provider and region (data center) of your choice.
  • The open-source project “Kyma” installed in its latest version on the provisioned cluster.

Serverless module

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.

 

Implementation

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:

Database module

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,…

Main server module

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:

  • Get all returns history.
  • Get the returns history for a specific user id.
  • Post a new return.

The services consumed by this main module are:

  • SAP HANA Cloud to read and write into the returns history table.
  • SAP Returnable Packaging Management industry cloud APIs to post the return document for each return into SAP Returnable Packaging Management and cascade it to S/4 HANA Cloud backend if required.

If you want to get the full code of our Kyma serverless function please check our Git repository.

Other blogs for more details about this use case

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

Useful References

Here are some links to additional resources that can get you up to speed with Kyma.

Learn

Implement

Engage

Scroll to Top